/* ====================================================================================

	Author					:			Ciplex (Melech Mizrachi)
	Author URI				:			http://ciplex.com (http://melechmizrachi.com)
	Copyright				:			Zivelo 2011 All Rights Reserved
	Description				:			Zivelo
	Designed by				:			Ciplex (http://ciplex.com)
	Hand-coded by			:			Ciplex (http://ciplex.com)
	Theme					:			Zivelo

	Table of Contents:
	
	1.									Global Functions
	2.									Homepage
	3.									All Categories
	4.									Content Pages
	5.									Product Page
	6.									Industry Page

==================================================================================== */

var jq = jQuery;

function hideModelDropdown() {
		jq(".homepage-products div.product-dropdown").hide();
		jq(".homepage-products li.active").removeClass("active");
		jq("div#by-industry-dropdown").hide();
		jq("div#by-model-dropdown").hide();
		//homepageSliderInterval = setInterval("homepageSlider()", 5000);
}

jq(document).ready(function( $ ) {
	
/* ====================================================================================

	1. Global Functions

==================================================================================== */

	$(".header .number").hover( function() {
			$(this).html("1-877-494-8356");
	}, function() {
			$(this).html("1-877-4-ZIVELO");
	});
	
	$("div#quote-form form div.submit input").click( function() {
			var name = $("#quote-form #first_name").val(),
				email = $("#quote-form #email").val(),
				last_name = $("#quote-form #last_name").val(),
				company = $("#quote-form #company").val(),
				phone = $("#quote-form #phone").val(),
				theThis = this;
				
			if ( name == "" || email == "" || last_name == "" || company == "" || phone == "" ) {
					$("#quote-form .textwidget").prepend('<p style="float:left;">Please provide values for all inputs with an asterisk (*)<br /><br />&nbsp;</p>');
					return false;
			}
	});
	
	var hideModelDropdowns = setTimeout( "hideModelDropdown()", 100);
	
	$("#open-by-model-dropdown a").hover( function( e ) {
			clearTimeout( hideModelDropdowns );
			$(".homepage-products div.product-dropdown").hide();
			$(".homepage-products li.active").removeClass("active");
			
			var theID = $(this).parent().attr('id').substr(5);
			$("div#by-industry-dropdown").hide();
			$("div#"+theID).show();
			clearInterval(homepageSliderInterval);
			
	}, function() {
			hideModelDropdowns = setTimeout( "hideModelDropdown()", 700);
			homepageSliderInterval = setInterval(homepageSlider, 5000);
	});
	
	$("#open-by-industry-dropdown a").hover( function( e ) {
			clearTimeout( hideModelDropdowns );
			$(".homepage-products div.product-dropdown").hide();
			$(".homepage-products li.active").removeClass("active");
			
			var theID = $(this).parent().attr('id').substr(5);
			$("div#by-model-dropdown").hide();
			$("div#"+theID).show();
			clearInterval(homepageSliderInterval);
			
	}, function() {
			hideModelDropdowns = setTimeout( "hideModelDropdown()", 700);
			homepageSliderInterval = setInterval(homepageSlider, 5000);
	});
	
	$("div#by-model-dropdown").hover( function() {
			clearInterval(homepageSliderInterval);
			clearTimeout( hideModelDropdowns );
	}, function() {
			$("div#by-industry-dropdown").hide();
			$(this).hide();
			homepageSliderInterval = setInterval(homepageSlider, 5000);
	});
	
	$("div#by-industry-dropdown").hover( function() {
			clearInterval(homepageSliderInterval);
			clearTimeout( hideModelDropdowns );
	}, function() {
			$(this).hide();
			homepageSliderInterval = setInterval(homepageSlider, 5000);
	});
	
	$("#by-model-dropdown ul.product-lines li a").hover( function( e ) {
		
		var theID = $(this).attr('id').substr(5);
		
		$("#by-model-dropdown div.latest-products").show();
		
		$("div#"+theID).show();
		
	}, function() {
		
		var theID = $(this).attr('id').substr(5);
		
		$("div#"+theID).hide();
		$("#by-model-dropdown div.latest-products").hide();
		
	});
	
/* ====================================================================================

	2. Homepage

==================================================================================== */
	
	if ( $("html").hasClass("homepage") ) {
		var homepageSliderInterval = setInterval(homepageSlider, 5000);
		/*var logos1Interval = setInterval(logos1, 8100);
		var logos2Interval = setInterval(logos2, 7500);
		var logos3Interval = setInterval(logos3, 3300);
		var logos4Interval = setInterval(logos4, 5200);
		var logos5Interval = setInterval(logos5, 6000);
		var logos6Interval = setInterval(logos6, 4400);*/
		var logos1Interval = setInterval(logos1, 4000);
		var logos2Interval = setInterval(logos2, 4000);
		var logos3Interval = setInterval(logos3, 4000);
		var logos4Interval = setInterval(logos4, 4000);
		var logos5Interval = setInterval(logos5, 4000);
		var logos6Interval = setInterval(logos6, 4000);
		var hideDropdowns = setTimeout( hideDropdown, 100);
	}
	
	function logos1() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $("div.footer-wrap div.footer ul.logos li a.active").attr('id').substr(7),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNewNum == 4 ) {
					theNewNum = 1;
			}
			
			$("div.footer-wrap div.footer ul.logos li.logos-first a.active").fadeOut(600, function() {
				$("div.footer-wrap div.footer ul.logos li.logos-first a.active").removeClass("active");
				$("div.footer-wrap div.footer ul.logos li a#logos1-"+theNewNum).fadeIn(600, function() {
						$("div.footer-wrap div.footer ul.logos li a#logos1-"+theNewNum).addClass("active");
				});
			});
		}
	}
	function logos2() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $("div.footer-wrap div.footer ul.logos li a.active").attr('id').substr(7),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNewNum == 4 ) {
					theNewNum = 1;
			}
			
			$("div.footer-wrap div.footer ul.logos li.logos-second a.active").fadeOut(600, function() {
				$("div.footer-wrap div.footer ul.logos li.logos-second a.active").removeClass("active");
				$("div.footer-wrap div.footer ul.logos li a#logos2-"+theNewNum).fadeIn(600, function() {
						$("div.footer-wrap div.footer ul.logos li a#logos2-"+theNewNum).addClass("active");
				});
			});
		}
	}
	function logos3() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $("div.footer-wrap div.footer ul.logos li a.active").attr('id').substr(7),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNewNum == 4 ) {
					theNewNum = 1;
			}
			
			$("div.footer-wrap div.footer ul.logos li.logos-third a.active").fadeOut(600, function() {
				$("div.footer-wrap div.footer ul.logos li.logos-third a.active").removeClass("active");
				$("div.footer-wrap div.footer ul.logos li a#logos3-"+theNewNum).fadeIn(600, function() {
						$("div.footer-wrap div.footer ul.logos li a#logos3-"+theNewNum).addClass("active");
				});
			});
		}
	}
	function logos4() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $("div.footer-wrap div.footer ul.logos li a.active").attr('id').substr(7),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNewNum == 4 ) {
					theNewNum = 1;
			}
			
			$("div.footer-wrap div.footer ul.logos li.logos-fourth a.active").fadeOut(600, function() {
				$("div.footer-wrap div.footer ul.logos li.logos-fourth a.active").removeClass("active");
				$("div.footer-wrap div.footer ul.logos li a#logos4-"+theNewNum).fadeIn(600, function() {
						$("div.footer-wrap div.footer ul.logos li a#logos4-"+theNewNum).addClass("active");
				});
			});
		}
	}
	function logos5() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $("div.footer-wrap div.footer ul.logos li a.active").attr('id').substr(7),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNewNum == 4 ) {
					theNewNum = 1;
			}
			
			$("div.footer-wrap div.footer ul.logos li.logos-fifth a.active").fadeOut(600, function() {
				$("div.footer-wrap div.footer ul.logos li.logos-fifth a.active").removeClass("active");
				$("div.footer-wrap div.footer ul.logos li a#logos5-"+theNewNum).fadeIn(600, function() {
						$("div.footer-wrap div.footer ul.logos li a#logos5-"+theNewNum).addClass("active");
				});
			});
		}
	}
	function logos6() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $("div.footer-wrap div.footer ul.logos li a.active").attr('id').substr(7),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNewNum == 4 ) {
					theNewNum = 1;
			}
			
			$("div.footer-wrap div.footer ul.logos li.logos-sixth a.active").fadeOut(600, function() {
				$("div.footer-wrap div.footer ul.logos li.logos-sixth a.active").removeClass("active");
				$("div.footer-wrap div.footer ul.logos li a#logos6-"+theNewNum).fadeIn(600, function() {
						$("div.footer-wrap div.footer ul.logos li a#logos6-"+theNewNum).addClass("active");
				});
			});
		}
	}
		
	function homepageSlider() {
		if ( $("html").hasClass("homepage") ) {
			var theID = $(".homepage-slider .controls-wrap li.active").attr('id').substr(14),
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1,
				theScroll = theNumber * ( -960 );
			
			if ( theNumber == 5 ) {
					theNewNum = 1;
					theScroll = 0;
			}
			
			$(".homepage-slider .controls-wrap li.active").removeClass("active");
			$(".homepage-slider .controls-wrap li#slideto-slide-"+theNewNum).addClass("active");
			
			$(".homepage-slider .slides-wrap .slides").animate( { 'left': theScroll }, 600 );
		}
	}
	
	$(".homepage-slider .controls-wrap li a").click( function ( e ) {
		
			clearInterval(homepageSliderInterval);
			
			var theID = $(this).parent().attr('id').substr(14),
				theNumber = new Number( theID ),
				theScroll = ( theNumber - 1 ) * ( -960 );
			
			$(".homepage-slider .controls-wrap li.active").removeClass("active");
			$(".homepage-slider .controls-wrap li#slideto-slide-"+theNumber).addClass("active");
			
			$(".homepage-slider .slides-wrap .slides").animate( { 'left': theScroll }, 600);
			homepageSliderInterval = setInterval(homepageSlider, 5000);
			
			e.preventDefault();
	});
	
	$(".homepage-products .products-nav li a").hover( function( e ) {
			
			var theID = $(this).parent().attr('id').substr(5);
			
			clearTimeout( hideDropdowns );
			clearInterval(homepageSliderInterval);
			
			$(".homepage-products li.active").removeClass("active");
			
			$(this).parent().addClass("active");
			$(".homepage-products div.product-dropdown").hide();
	
			$(".homepage-products div#"+theID).show();
			
	}, function( e ) {
			hideDropdowns = setTimeout( hideDropdown, 700);
			homepageSliderInterval = setInterval(homepageSlider, 5000);
	});
	
	function hideDropdown() {
			$(".homepage-products div.product-dropdown").hide();
			$(".homepage-products li.active").removeClass("active");
	}
	
	$(".homepage-products div.product-dropdown").hover( function() {
			clearInterval(homepageSliderInterval);
			clearTimeout( hideDropdowns );
	}, function() {
			$(".homepage-products div.product-dropdown").hide();
			$(".homepage-products li.active").removeClass("active");
			homepageSliderInterval = setInterval(homepageSlider, 5000);
	});
	
	$('div.product-dropdown div.product-list div.arrow a').live('click', function( e ) {
			
			var theClass = $(this).attr("class"),
				theProductList = $(this).parent().parent(),
				theProds = new Number( $(theProductList).find('div.products ul li').length ),
				theBottom = 0,
				theTop = $(theProductList).find('div.products ul').css("top");
				
			if ( theTop != "auto" ) {
				theTop = theTop.replace('px', ''),
				theTop = new Number(theTop);
			} else {
				theTop = 0;
			}
			
			var theNewTop = theTop + 265,
				theNewBottom = theTop - 265;
			
			theBottom = ( ( theProds / 3 ) * ( -265 ) ) + 265;
			
			if ( theClass == "top" && theTop != 0 ) {
				$(theProductList).find('div.products ul').animate( { 'top': theNewTop }, 600);
			} else if ( theClass == "bottom" && theBottom < theTop ) {
				$(theProductList).find('div.products ul').animate( { 'top': theNewBottom }, 600);
			}
			
			e.preventDefault();
	});
	
/* ====================================================================================

	3. All Categories

==================================================================================== */
	
	$('.category-section .products-list').each( function( i ) {
		var theFullWidth = new Number( $(this).find('.product-wrap li').length );
			theFullWidth = theFullWidth * 155;
		
		$(this).find('.product-wrap').css('width',theFullWidth);
		
		$(this).jScrollPane({scrollbarWidth:5, animateTo:true, horizontalTrackWidth:737});
	});
	
/* ====================================================================================

	4. Content Pages

==================================================================================== */

	if ( $("body").hasClass("page-id-10") ) {
		var aboutSliderInterval = setInterval(aboutSlider, 5000);
	}
	function aboutSlider() {
		if ( $("body").hasClass("page-id-10") ) {
			var theID = $("div.page-content div.content div.slideshow ul li.active").attr('id').substr(16),
				theTotalNumber = $("div.page-content div.content div.slideshow ul li").length,
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1;
			
			if ( theNumber == theTotalNumber ) {
					theNewNum = 1;
			}
			
			$("div.page-content div.content div.slideshow ul li#slideshow-image-"+theNumber).fadeOut(600, function() {
					$("div.page-content div.content div.slideshow ul li#slideshow-image-"+theNewNum).fadeIn(600, function(){
							$("div.page-content div.content div.slideshow ul li.active").removeClass("active");
							$("div.page-content div.content div.slideshow ul li#slideshow-image-"+theNewNum).addClass("active");
					});
			});
		}
	}
	
	$("div.page-content div.content div.slideshow a.arrow").click( function ( e ) {
		
			clearInterval(aboutSliderInterval);
			
			var theID = $("div.page-content div.content div.slideshow ul li.active").attr('id').substr(16),
				theTotalNumber = $("div.page-content div.content div.slideshow ul li").length,
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1,
				theOldNum = theNumber - 1;
			
			if ( theNumber == theTotalNumber ) {
					theNewNum = 1;
			} 
			if ( theOldNum == 0 ) {
					theOldNum = theTotalNumber;
			}
			if ( $(this).hasClass("left-arrow") ) {
					theNewNum = theOldNum;
			}
			
			$("div.page-content div.content div.slideshow ul li#slideshow-image-"+theNumber).fadeOut(600, function() {
					$("div.page-content div.content div.slideshow ul li#slideshow-image-"+theNewNum).fadeIn(600, function(){
							$("div.page-content div.content div.slideshow ul li.active").removeClass("active");
							$("div.page-content div.content div.slideshow ul li#slideshow-image-"+theNewNum).addClass("active");
					});
			});
			
			aboutSliderInterval = setInterval(aboutSlider, 5000);
			
			e.preventDefault();
	});
	
/* ====================================================================================

	5. Product Page

==================================================================================== */
	
	$("#quote-form select").selectBox();
			
	$("a.interested").click( function( e ) {
		
			$("#quote-form").fadeIn(600);
			clearInterval(homepageSliderInterval);
			$("html").scrollTo( 0, 600 );
			
			e.preventDefault();
	});
	
	$("#quote-form a.close-form").click( function( e ) {
		
			$("#quote-form").fadeOut(600, function() {
				$("#quote-form div.hidden").hide();
				$("#quote-form div.details a").html("Add more details").removeClass("hide");
			});
			
			homepageSliderInterval = setInterval(homepageSlider, 5000);
			
			e.preventDefault();
	});
	
	$("#quote-form div.details a").toggle( function( e ) {
			
			$("#quote-form div.hidden").show();
			$(this).html("Hide details").addClass("hide");
			e.preventDefault();
	}, function () {
			
			$("#quote-form div.hidden").hide();
			$(this).html("Add more details").removeClass("hide");
			e.preventDefault();
	});

	$("div.product div.slideshow a.arrow").click( function ( e ) {
			
			var theID = $("div.product div.slideshow ul li.active").attr('id').substr(16),
				theTotalNumber = $("div.product div.slideshow ul li").length,
				theNumber = new Number( theID ),
				theNewNum = theNumber + 1,
				theOldNum = theNumber - 1;
			
			if ( theNumber == theTotalNumber ) {
					theNewNum = 1;
			} 
			if ( theOldNum == 0 ) {
					theOldNum = theTotalNumber;
			}
			if ( $(this).hasClass("left-arrow") ) {
					theNewNum = theOldNum;
			}
			
			$("div.product div.slideshow ul li#slideshow-image-"+theNumber).hide();
			$("div.product div.slideshow ul li.active").removeClass("active");
			$("div.product div.slideshow ul li#slideshow-image-"+theNewNum).show();
			$("div.product div.slideshow ul li#slideshow-image-"+theNewNum).addClass("active");
			
			e.preventDefault();
	});
	
	$("div.details-content ul.details-nav li a").click( function( e ) {
		
			var theID = $(this).parent().attr('id').substr(5),
				theThis = this,
				offset = $(theThis).offset();
			
			$("div.details-content ul.details-nav li.active").removeClass("active");
			$(this).parent().addClass("active");
			
			$("div.main-content div.product div.details-content div.active").hide();
			$("div.main-content div.product div.details-content div.active").removeClass("active");
			$("div.main-content div.product div.details-content div#"+theID+"-tab").show();
			$("div.main-content div.product div.details-content div#"+theID+"-tab").addClass("active");
			$("html").scrollTo( offset.top - 50, 600 );
			
			e.preventDefault();
	});
	
	$("div.details-content div.tab-content ul.subnav li a").click( function( e ) {
		
			var theID = $(this).parent().attr('id').substr(5),
				theCurrentTab = $(this).parent().parent().parent(),
				theThis = this,
				offset = $(theThis).offset();
			
			$(theCurrentTab).find("ul.subnav li.current").removeClass("current");
			$(this).parent().addClass("current");
			
			$(theCurrentTab).find("div.sub-content-wrap div.current").hide();
			$(theCurrentTab).find("div.sub-content-wrap div.current").removeClass("current");
			$(theCurrentTab).find("div.sub-content-wrap div#"+theID+"-tab").show();
			$(theCurrentTab).find("div.sub-content-wrap div#"+theID+"-tab").addClass("current");
			$("html").scrollTo( offset.top - 50, 600 );
			
			e.preventDefault();
	});
	
	$("div.sub-content-wrap div.sub-tab div.logos-signage ul.logos-nav li a").click( function( e ) {
		
			var theID = $(this).parent().attr('id').substr(5),
				theCurrentTab = $(this).parent().parent().parent(),
				theThis = this,
				offset = $(theThis).offset();
			
			$(theCurrentTab).find("ul.logos-nav li.at").removeClass("at");
			$(this).parent().addClass("at");
			
			$(theCurrentTab).find("div.logos-content-wrap div.at").hide();
			$(theCurrentTab).find("div.logos-content-wrap div.at").removeClass("at");
			$(theCurrentTab).find("div.logos-content-wrap div#"+theID+"-tab").show();
			$(theCurrentTab).find("div.logos-content-wrap div#"+theID+"-tab").addClass("at");
			$("html").scrollTo( offset.top - 50, 600 );
			
			e.preventDefault();
	});
	
	$("div.gallery div.images-list ul.image-list li a").click( function( e ) {
		
			var theID = $(this).attr('id').substr(5),
				theCurrentTab = $(this).parent().parent().parent().parent().parent();
			
			$(theCurrentTab).find("ul.image-list li.active").removeClass("active");
			$(this).parent().addClass("active");
			
			$(theCurrentTab).find("div.images img.active").fadeOut( 600, function() {
					$(theCurrentTab).find("div.images img.active").removeClass("active");
					$(theCurrentTab).find("div.images img#"+theID).fadeIn(600, function() {
							$(theCurrentTab).find("div.images img#"+theID).addClass("active");
					});
			});
			
			e.preventDefault();
	});
	
	$('div.gallery div.images-list a.arrow').live('click', function( e ) {
			
			var theProductList = $(this).parent(),
				theProds = new Number( $(theProductList).find('ul li').length ),
				theBottom = 0,
				theTop = $(theProductList).find('ul').css("top");
				
			if ( theTop != "auto" ) {
				theTop = theTop.replace('px', ''),
				theTop = new Number(theTop);
			} else {
				theTop = 0;
			}
			
			var theNewTop = theTop + 400,
				theNewBottom = theTop - 400;
			
			theBottom = ( ( theProds / 3 ) * ( -400 ) ) + 400;
			
			if ( $(this).hasClass("top-arrow") && theTop != 0 ) {
				$(theProductList).find('ul').animate( { 'top': theNewTop+'px' }, 600);
			} else if ( $(this).hasClass("down-arrow") && theBottom < theTop ) {
				$(theProductList).find('ul').animate( { 'top': theNewBottom+'px' }, 600);
			}
			
			e.preventDefault();
	});
	
/* ====================================================================================

	6. Industry Page

==================================================================================== */
	
	
	$("div.main div.industry ul.industry-nav li a").click( function( e ) {
		
			var theID = $(this).parent().attr('id').substr(5);
			
			$("div.main div.industry ul.industry-nav li.active").removeClass("active");
			$(this).parent().addClass("active");
			
			$("div.industry-content-wrap div.active").hide( 600, function() {
					$("div.industry-content-wrap div.active").removeClass("active");
					$("div.industry-content-wrap div#"+theID).show(600, function() {
							$("div.industry-content-wrap div#"+theID).addClass("active");
					});
			});
			
			e.preventDefault();
	});
	
	$('.industry-content .products-list').each( function( i ) {
		var theFullWidth = new Number( $(this).find('.product-wrap li').length );
			theFullWidth = theFullWidth * 165;
		
		$(this).find('.product-wrap').css('width',theFullWidth);
		
		$(this).jScrollPane({scrollbarWidth:5, animateTo:true, horizontalTrackWidth:622});
	});
		
});
