$(function(){
	
	//home page news blocks under big image
	lastBlock = $(".newsBites .views-row-first .newsItem");
    firsBlock = $(".newsBites .views-row-first .newsItem");
    maxWidth = 252;
    minWidth = 25;	
	
	$(".newsBites li .newsItem").next(".imageFloat:first").animate({opacity: "show", top: "-130"}, "slow");
		
    $(".newsBites li .newsItem").hover(function(){
	    $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
		$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
		lastBlock = this;
		
		$(".newsBites li .newsItem").next(".imageFloat:first").animate({opacity: "hide", top: "-120"}, "fast");
		$(this).next(".imageFloat").animate({opacity: "show", top: "-130"}, "slow");
	}, function() {
	  $(this).next(".imageFloat").animate({opacity: "hide", top: "-120"}, "fast");
	});
	
	//cycle news blocks under big image
	function cycleNewsBites(){
		cycleBite=setInterval(function(){
			$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:700 });
			$(lastBlock).next(".imageFloat").animate({opacity: "hide", top: "-120"}, "fast");
			
			lastBlock = $(lastBlock).parent().next().find(".newsItem");
	
			if (lastBlock.length == 0) {
				lastBlock = firsBlock;
			} 
	
			
			$(lastBlock).animate({width: maxWidth+"px"}, { queue:false, duration:700});			
			$(lastBlock).next(".imageFloat:first").animate({opacity: "show", top: "-130"}, "slow");
			
		} ,3000);
		
		cycleImage=setInterval(function(){
		  $(lastBlock).next(".imageFloat").animate({opacity: "hide", top: "-120"}, "fast");
		} ,5900);
	}
	
	cycleNewsBites();

	$(".newsBites").hover(function(){	
		clearInterval(cycleBite);
		clearInterval(cycleImage);
	}, function(){	
		cycleNewsBites();
	});
	
    //overlayThumb hover effect
	$('.hover').hide();	
	$('.overlayThumb').hover(function() {						
			$(this).find('.hover').slideDown();
		}, function ()	{
			$(this).find('.hover').slideUp();			
	});

	//Product Images
	
   	//$('#slideshow1 p').cycle({ fx: 'fade', delay: '-2000'});
	//$('#slideshow2 p').cycle({ fx: 'fade', prev: '#prev', next: '#next', timeout: 0});
	$('#neffproduct').cycle({
		fx:     'fade', 
   		speed:  'fast', 
    	timeout: 0,
    	before:  onBefore, 
	   	after:   onAfter, 
    	pager:  '#productnav',
	    pagerAnchorBuilder: function(idx, slide) {
	        // return selector string for existing anchor
	        return '#productnav li:eq(' + idx + ') a';
	    }
	});
	function onBefore() { 
	    $('#colorwayName').animate({opacity: "hide"}, "fast"); 
	} 
	function onAfter() { 
	    $('#colorwayName').html(this.alt);
	    $('#colorwayName').animate({opacity: "show"}, "slow");
	}
	  
	//DEALER
	$("#edit-submit-DealersView").click(function() {		
		$("#onlineList").fadeOut();
		$("#internationalList").fadeOut();
		setTimeout(function(){$("#zipcodeList").fadeIn("slow");},500);
	});
	$("#searchOnline").click(function() {
		$("#zipcodeList").fadeOut();
		$("#internationalList").fadeOut();
		setTimeout(function(){$("#onlineList").fadeIn("slow");},500);
	});
	$("#searchInternational").click(function() {
		$("#zipcodeList").fadeOut();
		$("#onlineList").fadeOut();
		setTimeout(function(){$("#internationalList").fadeIn("slow");},500);
	});
	$("#zipcodeList").hide();
	$("#onlineList").hide();
	$("#internationalList").hide();
	

	//cycle slideshows
	$('#slideshow1 .view-content').cycle({ fx: 'fade', delay: '-2000'});
	$('#slideshow2 p').cycle({ fx: 'fade', delay: '-2000'});
	
	//header menu slide up text
	$("#headerMenu li").hover(function(){
		$(this).find('a').animate({top: "-15"}, "fast");
	}, function() {
	  $(this).find('a').animate({top: "0"}, "fast");
	});
	
	//special color box calls
	$(".colorboxBuyNow").colorbox({width:"260px",height:"300px", inline:true, href:"#buy_now_form"});
	$(".colorboxEmail").colorbox({width:"260px",height:"300px", inline:true, href:"#join_email_form"});
	$(".colorboxRequestAccess").colorbox({width:"350px",height:"400px", inline:true, href:"#request_access_form"});
	
	$(".views-row-1 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-1 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-1 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-1 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-2 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-2 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-2 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-2 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-3 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-3 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-3 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-3 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-4 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-4 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-4 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-4 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-5 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-5 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-5 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-5 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-6 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-6 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-6 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-6 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-7 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-7 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-7 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-7 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-8 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-8 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-8 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-8 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-9 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-9 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-9 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-9 .views-field-field-westvideofield-value .field-content"});
	$(".views-row-10 .views-field-field-eastthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-10 .views-field-field-eastvideofield-value .field-content"});
	$(".views-row-10 .views-field-field-westthumbnail-fid").colorbox({width:"545px",height:"490px", inline:true, href:".views-row-10 .views-field-field-westvideofield-value .field-content"});

	// Add pdf icons to pdf links
	$(".mediaDownload a[href$='.pdf']").addClass("pdf");
	 
	// Add txt icons to document links (doc, rtf, txt)
	$(".mediaDownload a[href$='.jpg'], .mediaDownload a[href$='.png'], .mediaDownload a[href$='.gif']").addClass("image");

	// Add zip icons to Zip file links (zip, rar)
	$(".mediaDownload a[href$='.zip'], .mediaDownload a[href$='.rar']").addClass("zip");
	
	// Add zip icons to EPS file links (eps)
	$(".mediaDownload a[href$='.eps']").addClass("eps");
	
	// Add zip icons to EPS file links (eps)
	$(".mediaDownload a[href$='.ai']").addClass("ai");
	
	// Add txt icons to document links (doc, rtf, txt)
	$(".mediaDownload a[href$='.doc'], .mediaDownload a[href$='.txt'], .mediaDownload a[href$='.rft']").addClass("txt");
	
	$("#randomTweets").tweet({
      count: 4,
      username: ["snoopdogg","scottylago","ALOUIEVITO","annefloremarxer","bbiebel","torsteinhorgmo", "Neff_Headwear"],
      loading_text: "loading randomness..."
	});
	
	//media_access
	$('.insideFolder').hide();
	$('.folder').addClass('closed');
	$('.folder h5').click(function(){
		
		if ($(this).next('.insideFolder').is(":hidden")) {
			$(this).next('.insideFolder').slideDown('slow');
			$(this).parent().removeClass('closed');
		} else {
			$(this).next('.insideFolder').slideUp('slow');
			$(this).parent().addClass('closed');
		}
	});
	
	//home page bucket rotate
	$('#bucketCarousel').carousel('#previous', '#next');
	
	//The auto-scrolling function
	function slide(){
	  $('#next').click();
	}
	//Launch the scroll every 2 seconds
	var intervalId = window.setInterval(slide, 3000);
	$("#bucketCarousel").hover(
		function () {	window.clearInterval(intervalId);intervalId=null;}, 
		function () {	intervalId = window.setInterval(slide, 3000);}
	);
	$("#next").hover(
		function () {	window.clearInterval(intervalId);intervalId=null;}, 
		function () {	intervalId = window.setInterval(slide, 3000);}
	);
	$("#previous").hover(
		function () {	window.clearInterval(intervalId);intervalId=null;}, 
		function () {	intervalId = window.setInterval(slide, 3000);}
	);

 	
 	
	$("#usaButton").corner("top 5px");
	$("#internationalButton").corner("top 5px");

		
});


