var tnews;
var tcurr=0;
var tpause = 0;

$(document).ready(function(){
   $("#nav > li > ul").fadeOut("fast");
   $("#nav li").hover(
      function(){ $(this).find("ul").fadeIn("fast"); }, 
      function(){ $(this).find("ul").fadeOut("fast"); } 
   );
   if (document.all) {
      $("#nav li").hoverClass("sfhover");
   }
   // png fix
   $('ul#nav li').pngFix();   
   
   // news ticker
    var tickerSelector = "ul#scTicker li";
	
    tnews = $(tickerSelector).hide().hover(
        function(){
            $(this).addClass("hovered");
            tpause=1;
        },
        function(){
            $(this).removeClass("hovered");
            tpause=0;
        }
    ).filter(":eq(0)").show().add(tickerSelector).size();
    setInterval(tickFunc,4000); //time in milliseconds 
	
	$(".itemquantity select").each(function(){
		$(this).change(function(){
			var reg = /[0-9]/
			var res = reg.exec($(this).get(0).name);
			if($(this).get(0).selectedIndex != 0){
				$("#optcont"+res+" select").addClass("required");
			}
		})
	});
	
	$(".itemquantity-main select").each(function(){
		$(this).change(function(){
			if($(this).get(0).selectedIndex != 0){
				$("#optcont0 select").addClass("required");
			} else {
				$("#optcont0 select").removeClass("required error");
				$("#optcont0 label").remove();
			}
		});
		if($(this).get(0).selectedIndex != 0) {
			$("#optcont0 select").addClass("required");
		}
	});
	
	
	// item page validation
	//$("#orderForm").validate();
	/*$("#orderForm").validate({
	 	beforeSubmit: function() {
	   		if (!$("#orderForm").validate().form()) {
				return false;	
			}
	 	}
	});*/
	
	/*$("#orderForm").validate({
   		submitHandler: function(form) {
			$("#atcbtn1").click();
		}
	}); */
	

});
// hover function
$.fn.hoverClass = function(c) {
   return this.each(function(){
      $(this).hover( 
         function() { $(this).addClass(c); },
         function() { $(this).removeClass(c); }
      );
   });
};
// news ticker function
function tickFunc() {
	if(tpause==0){
		$("#scTicker li:eq("+tcurr+")").fadeOut(400);
		tcurr = ++tcurr%tnews;
		$("#scTicker li:eq("+tcurr+")").fadeIn(1000); 
	}

} 

function frmchk(frm) {
	var count = 0;
	$(".iteminfo .product-info-table select").each( function() {
		$(this).css("border","1px solid #7F9DB9");
		if($(this).get(0).selectedIndex == 0 && $(this).attr("class") == "required") {
			$(this).css("border","2px solid #DD4537");
			count++;
		}
	});
	if (count > 0) {
		alert ("Please choose from the required option(s)");
		return false;
	}
	else
		return true;
}
