$(document).ready(function(){
						   
	// :hover for IE6
	$('#menu ul > li:has(ul)').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); }
	);
	
	/* home ad randmize */
	/*$('#ads ul li.ad4 a, #ads ul li.ad5 a').css('display', 'none');
	var randnum = Math.floor(Math.random() * 2);
	
	if (randnum == 1) {
		$('#ads ul li.ad4 a').css('display', 'block');
	} else {
		$('#ads ul li.ad5 a').css('display', 'block');	
	}*/
	
	
	// Accordion
	/*var hArray = new Array();
	$("ul.accordion li h4 > a").each(function(i) {
		// store 100% height to array
		//hArray[i] = $(this).next("div").css("height"); // return XXpt
		hArray[i] = $(this).parent().next("div").height();
	});
	
	$("ul.accordion li div").css({height:"0", overflow: "hidden"});
	
	$("ul.accordion li h4 > a").each(function(i) {
		
		$(this).click(function() {
			$(this).removeAttr("href");
			$(this).css("cursor","pointer");
			
			var countOpen = $("ul.accordion li.opened").length;
			
			var curHeight = $(this).parent().next("div").height(); // return int
			
			if (curHeight == 0) {
				$(this).parent().parent().addClass("opened");
				$(this).parent().next("div").animate({
					height: hArray[i]+"px"
				},500);
			} else {
				$(this).parent().parent().removeClass("opened");
				$(this).parent().next("div").animate({
					height: "0"
				},500);
			}
		});
	});*/
	
	var hArray = new Array();
	var nArray = new Array();
	var oArray = new Array();
	$("ul.accordion li h4 > a").each(function(i) {
		// store 100% height to array
		//hArray[i] = $(this).next("div").css("height"); // return XXpt
		hArray[i] = $(this).parent().next("div").height();
		nArray[i] = i+1;
	});
	
	$("ul.accordion li div").css({height:"0", overflow: "hidden"});
	
	$("ul.accordion li h4 > a").each(function(i) {
		
		$(this).click(function() {
			$(this).removeAttr("href");
			$(this).css("cursor","pointer");
			
			var countOpen = $("ul.accordion li.opened").length;
			
			var curHeight = $(this).parent().next("div").height(); // return int
			
			if (curHeight == 0) {
				$(this).parent().parent().addClass("opened");
				$(this).parent().next("div").animate({
					height: hArray[i]+"px"
				},500);
			} else {
				$(this).parent().parent().removeClass("opened");
				$(this).parent().next("div").animate({
					height: "0"
				},500);
			}
			
			oArray = []; //empty array
			oArray = nArray.slice(); // copy array
			oArray.splice(i, 1); //remove clicked item
			if (countOpen == 1) {
				for (var j=0; j<oArray.length; j++) {
					$("ul.accordion li:nth-child(" + oArray[j] + ")").removeClass("opened");
					$("ul.accordion li:nth-child(" + oArray[j] + ") div").animate({ height: "0"}, 500);
				}
			}
		});
	});
	
	$(".open-all a").toggle(
		function() {
			$(this).addClass("opened");
			$(this).removeAttr("href");
			$(this).css("cursor","pointer");
			$("ul.accordion li div").each(function(i) {
				$(this).parent().addClass("opened");
				$(this).animate({
						height: hArray[i]
				},500);								   
			});
		},
		function() {
			$(this).removeClass("opened");
			$(this).removeAttr("href");
			$(this).css("cursor","pointer");
			$("ul.accordion li").removeClass("opened");
			$("ul.accordion li div").animate({
				height: "0"
			},500);
		}
	);

	
	/* lightbox */
	if (jQuery().lightBox) {
		$('a.lightbox').lightBox();
		$('a.lightbox2').lightBox();
	}
	/* product page category menu */
	/*if ($("#category ul > li > ul > li a.activeLi")) {
		$("#category ul > li > ul > li a.activeLi").parent().parent().parent().children().css("font-weight","bold");
		$("#category ul > li > ul > li a").css("font-weight","normal");
	}
	
	if ($("#category ul > li > ul > li > ul > li a.activeLi")) {
		$("#category ul > li > ul > li > ul > li a.activeLi").parent().parent().parent().parent().parent().children().css("font-weight","bold");
		$("#category ul > li > ul > li > ul > li a.activeLi").parent().parent().parent().children().css("font-weight","bold");
		$("#category ul > li > ul > li > ul > li a").css("font-weight","normal");
	}*/
	
	/* Cart */
	$("#cart a#get-quote-btn").click(function() {
		var textarea_comment = $("#cart textarea[name='comment']").val();
		window.location.href = "index.php?route=checkout/shipping&comment="+escape(textarea_comment)+"";
	});
	
	/* sezrch toggle*/
	
	$("#module-search").hide();
	$("a#search-toggle").toggle(
		function() {
			//$(this).removeAttr("href");
			$("#module-search").slideDown("slow");
		},
		function() {
			//$(this).attr("href", "#");
			$("#module-search").slideUp("slow");
		}
	);
	
	
	
	/* industry solutions page */
	/*var flag = true;
	function hide_all_article() {
		$("body.industry-solutions-page #main-content > div").each(function(i) {
			$("body.industry-solutions-page .article"+(i+1)).css("display", "none");
		});
		if (flag == true) {
			flag = false;
		} else {
			$("body.industry-solutions-page .article0").css("display", "none");	
		}
	}
	
	hide_all_article();
	
	function remove_all_active_class() {
		$("body.industry-solutions-page .submenu ul li a").each(function(i) {
			$(this).removeClass("active");
		});
	}
	
	$("body.industry-solutions-page .submenu ul li a").each(function(i) {
		$(this).click(function() {
			hide_all_article();
			remove_all_active_class();
			$(this).removeAttr("href");
			
			$("body.industry-solutions-page .article"+(i+1)).fadeIn("slow");
			$(this).addClass("active");
			
		});
	});
	
	$("body.industry-solutions-page .submenu h3 a").click(function() {
		 hide_all_article();
		remove_all_active_class();
		$(this).removeAttr("href");
		
		$("body.industry-solutions-page .article0").fadeIn("slow");
	});*/
	
	/* Meet our team window */
	$('h6.box-meet-our-team a').click(function() { 
        $.blockUI({ 
			message: $('#meet-our-team-info'),
			css: { 
				padding:        0,
				margin:         0, 
				width:          '462px',
				top:            '20px', 
				left:           '35%', 
				textAlign:      'left', 
				/*color:          '#000',*/ 
				border:         'none', 
				backgroundColor:'transparent', 
				cursor:		  	 'default'
			},
			// styles for the overlay 
    		overlayCSS:  { 
        		backgroundColor: '#000', 
        		opacity:         0.7,
				cursor:		  	 'default'
    		} 
		}); 
	});
	
	$('#meet-our-team-info p a').click(function() { 
    	$.unblockUI(); 
        return false; 
    }); 
	
	// form
	var text_name = "Name:";
	var text_phone = "Phone:";
	var text_email = "Email:";
	var text_comments = "Comments:";
	
	var input_fullname = $("#contactForm input[name='fullname']");
	var input_phone = $("#contactForm input[name='phone']");
	var input_email = $("#contactForm input[name='email']");
	var input_comments = $("#contactForm textarea[name='comments']");
	
	if (input_fullname.val() == "") {
		input_fullname.val(text_name);
	}
	if (input_phone.val() == "") {
		input_phone.val(text_phone);
	}
	if (input_email.val() == "") {
		input_email.val(text_email);
	}
	if (input_comments.val() == "") {
		input_comments.val(text_comments);
	}
	
	/*$("#contactForm input[name='fullname']").val(text_name);
	$("#contactForm input[name='phone']").val(text_phone);
	$("#contactForm input[name='email']").val(text_email);
	$("#contactForm textarea[name='comments']").val(text_comments);*/
	
	input_fullname.focus(function() {
		if( $(this).val() == text_name ) {
			$(this).val("");
		}
	});
	input_phone.focus(function() {
		if( $(this).val() == text_phone ) {
			$(this).val("");
		}
	});
	input_email.focus(function() {
		if( $(this).val() == text_email ) {
			$(this).val("");
		}
	});
	input_comments.focus(function() {
		if( $(this).val() == text_comments ) {
			$(this).val("");
		}
	});
	
	input_fullname.blur(function() {
		if ($(this).val() == "") {
			$(this).val(text_name);	
		}
	});
	input_phone.blur(function() {
		if ($(this).val() == "") {
			$(this).val(text_phone);	
		}
	});
	input_email.blur(function() {
		if ($(this).val() == "") {
			$(this).val(text_email);	
		}
	});
	input_comments.blur(function() {
		if ($(this).val() == "") {
			$(this).val(text_comments);	
		}
	});
	
	$("#contactForm").submit(function() {
		if ( input_fullname.val() == text_name ) {
			input_fullname.val("");	
		}
		if ( input_phone.val() == text_phone ) {
			input_phone.val("");	
		}
		if ( input_email.val() == text_email ) {
			input_email.val("");	
		}
		if ( input_comments.val() == text_comments ) {
			input_comments.val("");	
		}
		
		if (formValidation($(this)) == false) {
			return false;	
		} else {
			return true;	
		}
	});
	

 
	
	
	
});
