$(document).ready(function(){
 	/*------------------- Galeries ------------------------------------------------------------------------*/
	//----------- Main Slideshow
	/*
	$('#specialOffer').cycle({ 
		fx:     'scrollUp', 
		speed:   1500, 
		timeout: 6000, 
		//next:   '#next',
        //prev:   '#prev',
		//before:  onBefore, 
		//after:   onAfter,
		cleartype:  1
	 });
	
	function onBefore(curr,next,opts) { 
		$(this).find('p').hide();
	}
	
	function onAfter(curr,next,opts) { 
		$(this).find('p').fadeIn();
	}
	
	$('#pause').click(function() { $('#slideshow').cycle('pause'); return false; });
    $('#play').click(function() { $('#slideshow').cycle('resume'); return false; });

	/*-----------------------------------------------------------------------------------------*/
	//Home content slider
	$("#panel #flowpanes").not('#panel.content #flowpanes').scrollable({
		size: 1,
		clickable: false,
		easing:	'easeOutExpo',
		speed: 1000
	}).mousewheel(1000);
	
	
	$('.box').hover(function() {
		var src = $(this).find('img.hoverable').attr("src").match(/[^\.]+/) + "_hover.gif";
        $(this).find('img.hoverable').attr("src", src);	
	},function() {
		var src = $(this).find('img.hoverable').attr("src").replace("_hover", "");
		$(this).find('img.hoverable').attr("src", src);	
	});
		
	/*---- Accordion ------------------------------------------------------------------------------*/
	$("#rightSidebar #accordion").not('#rightSidebar.pages #accordion').tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});	
	$("#rightSidebar.pages #accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: 0});
	
	/*---- Css ---------------------------------------------------------------------------------*/
	if (!$('#subNav').length) {
		var w = $('#content.pages').width();
		$('#content.pages').css({
			'width': w+180,
			'background' : 'none'
		});
	}
	/*-----------------------------------------------------------------------------------------*/
	$.easing.custom = function (x, t, b, c, d) { 
		var s = 1.70158;  
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	$.easing.easeOutExpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	};
	$.easing.easeOutBounce = function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};

	/*---------- FORMS --------------------------------------------------------------------------------------------*/
	
	//Search form validation
	$("form#ajaxSearch_form").submit(function() {
		if ( ($("input#ajaxSearch_input").val() == "") || ($("input#ajaxSearch_input").val() == "Search...")){
			my_alert('At least 3 characters are required for your search term.');
			return false;
		}
    });
	
	$("input[name='reset']").click( function() {
		$('#voice_bill').find('input[name!=submit], input[name!=reset]').val(''); 
	 	return false;
	});

	
	var status = $("input[name='meeting']:checked").val();
	if (status == 'Yes') {
		$('#meeting_details').show();
	}
	
	$("input[name='meeting']").click( function() {
	  var data = $("input[name='meeting']:checked").val();
	  if (data == 'Yes') {
	 	$('#meeting_details').slideDown();

	  } else {
		$('#meeting_details').slideUp();
	  }

	});
	
	/*---- gUIDES DOWNLOAD -----*/
	
	$("select#brand").change(function(){
		if ($(this).val() == '') {
			var options = '<option value="">Choose file</option>';
			$("select#guide").html(options);
		} else {
			$.getJSON("assets/snippets/guides_download/populate_fields.php",{id: $(this).val(), ajax: 'true'}, function(j){
				var options = '';
				for (var i = 0; i < j.length; i++) {
					options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
				}
				$("select#guide").html(options);
			})
		}
	});
  
  	$("form#guides_form").submit(function() {
		var guides = $("select#guide").val();
		if (guides == 0) {
			my_alert('No guides available for this brand');
			return false;
		} else {
			return true;
		}
    });
  

	
}); //Close document.ready

$(window).bind("load", function() {							
    //-----------  Preload images for 
	
	$('.loading').each(function () {
		$(this).hide();
	});
	$('#flowpanes').fadeIn('slow');

});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function my_alert(alert_content) {
	$('body').append('<div id="alert">'+alert_content+'<br /> <span class="close">Close</span></div>');
	$("#alert").overlay({ 
		top: 200, 
		expose: { 
			color: '#fff', 
			loadSpeed: 500, 
			opacity: 0.6 
		}, 
		closeOnClick: true,
		api: true 
	}).load();
}