$(document).ready(function(){

	//alert("test");

	

	/* ---------------------------------------------------------------------------- */

	/* scrolling image wall carousel */

	if ($('#mycarouselwall').length > 0 ){ // check if element is on page	

	

		function mycarouselwall_initCallback(carousel)

		{

			// Disable autoscrolling if the user clicks the prev or next button.

			carousel.buttonNext.bind('click', function() {

				carousel.startAuto(0);

			});

		

			carousel.buttonPrev.bind('click', function() {

				carousel.startAuto(0);

			});

		

			// Pause autoscrolling if the user moves with the cursor over the clip.

			carousel.clip.hover(function() {

				carousel.stopAuto();

			}, function() {

				carousel.startAuto();

			});

		};

		

		jQuery(document).ready(function() {

			jQuery('#mycarouselwall').jcarousel({

				auto: 5,
				
				scroll: 1,

				wrap: 'last',

				initCallback: mycarouselwall_initCallback

			});

		});

		

	}

	/* scrolling image wall carousel */

	/* ---------------------------------------------------------------------------- */





	/* ---------------------------------------------------------------------------- */

	/* scrolling farmshop carousel */

	if ($('#mycarouselfarm').length > 0 ){ // check if element is on page	

	

		function mycarouselwall_initCallback(carousel)

		{

			// Disable autoscrolling if the user clicks the prev or next button.

			carousel.buttonNext.bind('click', function() {

				carousel.startAuto(0);

			});

		

			carousel.buttonPrev.bind('click', function() {

				carousel.startAuto(0);

			});

		

			// Pause autoscrolling if the user moves with the cursor over the clip.

			carousel.clip.hover(function() {

				carousel.stopAuto();

			}, function() {

				carousel.startAuto();

			});

		};

		

		jQuery(document).ready(function() {

			jQuery('#mycarouselfarm').jcarousel({

				auto: 5,
				
				scroll: 1,

				wrap: 'last',

				initCallback: mycarouselwall_initCallback

			});

		});



	

		//Swap Image on Click

		$("#mycarouselfarm a").click(function() {		

			var mainImage = $(this).attr("href"); //Find Image Name

			//alert(mainImage);

			$("#mycarouselfarm-image img").attr({ src: mainImage });

			return false;		

		});



	}

	/* scrolling farmshop carousel */

	/* ---------------------------------------------------------------------------- */



	if ($('#menu-wrapper #header-menu').length > 0 ){ // check if element is on page	

			//alert("test");	

			

			/*//create hide wrapper events as array

			pageWrapper = ["#menu-wrapper #header-menu"];

			

			$(pageWrapper[0]).click(function() { 

				//Hide the all menus if visible 

				$('li.general').each(function(){

					$(this).children().hide();

				});

			});*/

			



			//apply overlay animations for none ie
			
			
			

				if($('li.general').length > 0 ){ // check if element is on page
					
					$('li.general').each(function(){				
	
						var over_top = 20;
	
						var start_top = -200;
	
						var time = 150;
	
						var hideDelay = 500;
	
						
	
						var hideDelayTimer = null;
	
			 
	
						var beingShown = false;
	
						var shown = false;
	
						
	
						var sub_menu = $(this).children('ul');
	
						
	
						if($(this).hasClass('nofade') == false){				
	
							
	
							//handle parent / child events
	
							$(this).mouseover(function(){
								
								var newHeight = '250px';

								switch($(this).children('a').attr('title')){
									case "story":
										newHeight = '230px';
									break;
									case "cheese":
										newHeight = '175px';
									break;
									case "product":
										newHeight = '180px';
									break;
									case "delivering":
										newHeight = '180px';
									break;
									case "export":
										newHeight = '165px';
									break;
								}

								sub_menu.css({'border':'1px solid #BAAC4E'});
								sub_menu.css({'border-top':'none'});
								sub_menu.css({'left':'-1px'});
								
								
								if (hideDelayTimer) clearTimeout(hideDelayTimer);					   
	
								if (beingShown || shown) {
	
									// don't trigger the animation again
	
									return;
	
								} else {
	
									 // reset position of info box
	
									beingShown = true;
	
								
	
									// reset position of info box based on sttyle sheet values
	
									sub_menu
									.css({'width':'227px'})
									.animate({width: '227px',height:newHeight,opacity:0.9}, 500, 'swing', function() {
	
										beingShown = false;
	
										shown = true;
	
									});
	
								}
	
							}).mouseout(function(){					
	
								
								if (hideDelayTimer) clearTimeout(hideDelayTimer);

								hideDelayTimer = setTimeout(function () {
	
									hideDelayTimer = null;
	
									sub_menu.animate({width: '227px', height: '0px'}, time, 'swing', function () {
	
										shown = false;
	
									});
	
								}, hideDelay);
	
							});
	
							
	
						}
	
					});
	
				}


	} 





	// bind the expansion/contraction to the toggleElement
	if(jQuery.fn.media && jQuery.fn.getLoadModalFlv){
		$('a.show-vid').loadModalFlv({
			imgDefaultSrc : '/css/skins/default/img/header/banner-1.gif'
		}); // options objBindToWrapper: ["div.col-1"], objBindTo: ["div.banner-item"], imgExtension: ["jpg"], imgDefaultSrc: null
	}

});


