$(function() {

	//Accomodation Slider
	$('.slider').cycle({
		fx: 'scrollHorz',
		width:            918,
		speed:            300,
		timeout:          0,
		activePagerClass: 'active',
		pager:            '.slider-nav',
		next:             '.slider-next',
		prev:             '.slider-prev',
		pagerAnchorBuilder: function(idx, slide) {
			// return sel string for existing anchor
			return '.slider-nav li:eq(' + (idx) + ') a';
		}

	});

	//Add intro paragraph
	$('h1').next('p').addClass('intro dark serif');

	//Lightbox
	$('a[rel*=lightbox]').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.75,
		containerBorderSize: 12,
		imageBlank:     '/assets/img/blank.gif',
		imageLoading:   '/assets/img/loading.gif',
		imageBtnClose:  '/assets/img/close.gif',
		imageBtnPrev:   '/assets/img/prev.gif',
		imageBtnNext:   '/assets/img/next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'of'
	});

	//Textbox label
	$(".textbox-label").each(function(){
		var theVal = $(this).val();
		var theLabel = $(this).attr('title');
		var theClass = 'textbox-has-label';
		if (theVal == '') $(this).val(theLabel);
		if (theVal != theLabel && theVal != '')  $(this).addClass(theClass);

		$(this).focus(function()
		{
			if ($(this).val() == theLabel)
			{
				$(this).val('');
				$(this).addClass(theClass);
			}
		}).blur(function()
		{
			if ($(this).val() == '') $(this).val(theLabel).removeClass(theClass);
			else $(this).addClass(theClass);
		});
	});
	$('form').submit(function(){
		$(".textbox-label").each(function(){
			if ($(this).val() == $(this).attr('title')) $(this).val('');
		});
	});

	// Custom dropdowns
	$.fn.extend({
		customStyle : function(options) {
			if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
				return this.each(function() {
					var currentSelected = $(this).find(':selected');
					$(this).after('<span class="selectbox-custom"><span class="selectbox-custom-inner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
					var selectBoxSpan = $(this).next();
					var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
					var selectBoxSpanInner = selectBoxSpan.find(':first-child');
					selectBoxSpan.css({display:'inline-block'});
					selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
					var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
					$(this).height(selectBoxHeight).change(function(){
						// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
					selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
						// Thanks to Juarez Filho & PaddyMurphy
					});
				});
			}
		}
	});
	$('.selectbox').customStyle();

});

