// JavaScript Document

var mytimeout;
var timerId = 0;
var counterId = 0;
var running = true;
var curImg;
var numimages;
var stateNum = 1;
var sectionState = 'web';
var theModelCarousel = null;
var func1;

jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){
			
	$('#wrapper').delay(1200).fadeIn();

	$("#accordion").accordion({ 
						collapsible: true, 
						active: sectnum, 
						autoHeight: false});
			
	/* image gallery large */
		startCulinary();

	
	
	$('.blogLink').click(function(){
		window.location = "blogs.php";
        return false; //  needs to be done to stop default accordion func
    });
	$('.venuesLink').click(function(){
		window.location = "venues.php";
        return false; //  needs to be done to stop default accordion func
    });
	$('.vendorsLink').click(function(){
		window.location = "vendors.php";
        return false; //  needs to be done to stop default accordion func
    });
	
	function setBtns(num) {
		num--;
		var htmlstring = '<div id="galpixbtn" class="pixon"></div>';
		for(i=0; i < num; i++) {
			htmlstring = htmlstring + '<div id="galpixbtn" class="pixoff"></div>';
		}
		
		$("#lggallerynav").html(htmlstring);
		
	}
	
	function startCulinary() {
	  clearMe();
	  running = true;
	  startTimer();
	  galtype = 'culinary';
	  curImg = 0;
	  numimages = culinaryimages.length;
	  setBtns(numimages);
	  var leftpos = ( 860 - ( numimages * 25 ) ) + "px";
	  var setwidth = ( numimages * 30 ) + "px";
	  $("#lggallerynav").css({ "left" : leftpos, "width" : setwidth });
	  setLink(0);
	  setClicks();
	  btnState(1);
	  loadImage(0);
	}
	
	


	function setClicks() {
	  $("#lggallerynav div").each(
		  function( intIndex ){
			  $( this ).bind (
				  "click",
				  function(){				
					  if(checkClass(this)) {
						  loadImage(intIndex);
						  btnState(intIndex+1);
						  curImg = intIndex+1;
						  running = false;
					  }
				  }
			  )
		  }
	  )
	}
	
	function checkClass(clip) {
		var cls = $(clip).attr('class');
		var val = cls.substring(3)
		if( val == "off") {
			return true;
		}
	}
	
	function btnState(num) {
		for(var i=0; i<numimages; i++) {
			$("#lggallerynav").find("div").eq(i).removeClass('pixon');
			$("#lggallerynav").find("div").eq(i).addClass('pixoff');
		}
			$("#lggallerynav").find("div").eq(num-1).addClass('pixon');
	}
	
	
	function setLink(num) {
		$("#galindex li a").each(
		  function( intIndex ){
	  		$("#galindex").find("li a").eq(intIndex).removeClass('galon');
		  }
		);
		$("#galindex").find("li a").eq(num).addClass('galon');

	}
	
	$('#galindex li a').click(function() {
									   		
		var index = $("#galindex li a").index(this);
		
		switch (index)
		{
		case 0:
		  startCulinary();
		  break;
		}

	});
	

	/* end image gallery large */
	
	
	/*------ CAROUSEL -----*/
	
	
	var pieces = $('.scrollcont').size();
	var vidpieces = $('.scrollcontvid').size();
	var totalpieces = pieces + vidpieces;
	var fullwidth = 303 * totalpieces;
	$("#scrollpanel ul").css({ "width" : fullwidth });
	var nextallow = true;
		
	
	$("#prevbtn").css({ "background-position" : "-36px 0px", "cursor" : "default" });
	
	$('#scrollwrapper').serialScroll({
		items:'li',
		start:0, //as we are centering it, start at the 2nd
		duration:400,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		step:3,
		exclude:3,
		onBefore:function( e, elem, $pane, $items, pos ){
			
			var num = totalpieces - pos;
			
			if(num == 4) {
				$("#nextbtn").css({ "background-position" : "-36px 0px", "cursor" : "default" });
				$("#prevbtn").css({ "background-position" : "0px 0px", "cursor" : "pointer" });
				nextallow = false;
			}
			if(pos == 0) {
				$("#prevbtn").css({ "background-position" : "-36px 0px", "cursor" : "default" });
				$("#nextbtn").css({ "background-position" : "0px 0px", "cursor" : "pointer" });
			} else if(pos != 0 && num != 4) {
				$("#prevbtn").css({ "background-position" : "0px 0px", "cursor" : "pointer" });
				$("#nextbtn").css({ "background-position" : "0px 0px", "cursor" : "pointer" });
			}
			
		},
		onAfter:function( e, elem, $pane, $items, pos ){
			
		//	$('#scrollvidinner').delay(1000).load('frontvid.php');

			
		}
	});
	
	$("#scrollwrapper").css({ "left" : "-1px" });
	
	
	$('#nextbtn').click(function() {
		var classTrue = $('#nextbtn').hasClass("nextbtn");
		if(nextallow == true) {
			$('#scrollwrapper').trigger('next');
			
				$("#scrollvidinner").each(
					function(){
						var cls = $(this).attr('name');
						$('#scrollvidinner').html('<iframe class="youtube-player" type="text/html" width="274" height="160" src="http://www.youtube.com/embed/'+cls+'" frameborder="0"></iframe>');
					}
				)
			
			
		}
		$("#scrollwrapper").css({ "left" : "0px" });
	});
	
	
	$('#prevbtn').click(function() {
		//var classTrue = $('#webprev').hasClass("prevbtn");
		//if(classTrue == true) {
			nextallow = true;
			$('#scrollwrapper').trigger('prev');
		//}
				$("#scrollwrapper").css({ "left" : "0px" });
	});
	
	$('.scrollcont').click(function() {
		var scrollclick = $('.scrolllink', this).attr('href');
		
		window.location = scrollclick;
	});
	

	
	
	/*------ END CAROUSEL -----*/
	
	
	
	function setThumbClicks() {
	  $(".thumb2").each(
		  function( intIndex ){
			  $( this ).bind (
				  "click",
				  function(){				
					  var vidid = $(this).attr('id');
					  var vidtitle = $(this).attr('title');
					  var viddesc = $("#viddesc", this).html();
					  $.prettyPhoto.open('frontvid.php?vid='+vidid+'&iframe=true&width=655&height=420',vidtitle,viddesc);
					  
					}
			  )
		  }
	  )
	}
	
	setThumbClicks();
	

	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: false, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_square',
		setCount:0
	});
	
	$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({ animationSpeed:'slow',theme: 'facebook' });
	

	
	
}); /* end jQuery*/


	function runGallery() {
		if(running == true) {
			curImg++;
			if(curImg == numimages) {
				curImg = 0;
			}
						  
			loadImage(curImg);
			curImg = curImg;
			
			$("#lggallerynav").find("div").eq(curImg-1).removeClass('pixon');
			$("#lggallerynav").find("div").eq(curImg-1).addClass('pixoff');
			$("#lggallerynav").find("div").eq(curImg).addClass('pixon');
			
			mytimeout = setTimeout("runGallery()",6000);
							
		}
		
		counterId++;
	}
	
	function loadImage(pix) {	
			var img = new Image();
			var path;
			
				path = culinaryimages[pix];
				$("#gallerytitle").html('<span class="galtitle">'+culinarytitles[pix]+'</span>');
			  	$("#gallerydescription").html(culinarydesc[pix]);
			
			
			$(img).load(function () {
				//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
				$(this).hide();
				$('#loader').html('');
				$('#loader').removeClass('loading').append(this);
				
				$(this).fadeIn();
			}).error(function () {
				// notify the user that the image could not be loaded
			}).attr('src', path );
		};
		
		
		
	function startTimer() {
	  mytimeout = setTimeout("runGallery()",6000);
	 }
	
	function clearMe() {
	  counterId = 0;
	  clearTimeout ( mytimeout );
	}

