var klondike = {};
klondike.ui = 
	{	
		init : function()
			{
			klondike.ui.scrollBar();
			klondike.ui.selectBox();
			klondike.ui.checkboxs();
			klondike.ui.productNav();
			klondike.ui.popup();
			klondike.ui.chek_Mutual.init();
			
			},
		scrollBar: function()
			{
				if($('body *').hasClass('scroll-pane'))
					{
						$('.scroll-pane').jScrollPane({showArrows: true});
					}
			},
		selectBox: function () 
			{
			 var sNum=document.getElementsByTagName("select");
			 if (sNum.length!=0) {
					 $('select').sSelect();
	        	} else { return false;  }
	   		},
		checkboxs:  function()
				{
					var _pObj = 'input[type="checkbox"]';
					var _cAt = 'check-box-active'
					
					$("input:checked").next().addClass(_cAt);
					$(_pObj).live("click", function () {
						if($(this).is(":checked")) {
								$(this).next().addClass(_cAt);
						} else 	{ $(this).next().removeClass(_cAt);}
					});
					$(_pObj).focusin(function() {
						$(this).next().addClass('chekbox_focus');
					});
					$(_pObj).focusout(function() {
						$(this).next().removeClass('chekbox_focus');
					});
								
				},
			chek_Mutual:
					{
						init:  function()
							{
								var _srcId = ".check-box-0";
						       	var _trgId = ".check-box-1";
								$(_srcId).click(function(){
									klondike.ui.chek_Mutual._isValid(_srcId,_trgId);	
								});
								
								$(_trgId).click(function(){
									klondike.ui.chek_Mutual._isValid(_trgId,_srcId);
								})
							
							},
							_isValid: function(parent_id, target_id)
							{
								if(!$(parent_id).hasClass('check-box-active')) {
									if($(target_id).hasClass('check-box-active')) {
										$(target_id).removeClass('check-box-active');
										$(target_id).prev().attr('checked','');
									}
								}
							}	
					},
		
		activeFooter: function() 
				{
					var _obTg = $('footer li a').attr('href');
					var _bdCls = $('body').attr('class');
					var patt1=/thankyou/gi;
					
					if(_bdCls.match(patt1)=="thankyou") {
						_bdCls=_bdCls.split(" ");
						_bdCls=_bdCls[0];
					}
					if(_bdCls!="") {
					$('footer li a').each(function(){
					var _obSrc = $(this).attr('href');						   
						_obSrc = _obSrc.split("/");
						if(_obSrc[1]==_bdCls) {
							$(this).addClass('active')
						}
					})	
					} else { return false;}
							
				},
		productNav: function(){
			
				$("a.ingr").click(function(){
					
					if(!$(this).parent().find('h2').hasClass()) {
						$(this).parents('.left-con').next().children().find('.prod-info').hide();
						$(this).parent().find('h2').addClass('active');
						
					}
					$(this).next().removeClass('nutr-act');
					$(this).addClass('ingr-act');
					$(this).parents('.left-con').next().children().find('.ingr-info').show();
					$(this).parents('.left-con').next().children().find('.nutr-info').hide();
					$(this).parents('.left-con').next().children().find('.scroll-pane2').jScrollPane({showArrows: true});
				});
				$("a.nutr").click(function(){
					if(!$(this).parent().find('h2').hasClass()) {
						$(this).parents('.left-con').next().children().find('.prod-info').hide();
						$(this).parent().find('h2').addClass('active');
						
					}
					$(this).prev().removeClass('ingr-act');
					$(this).addClass('nutr-act');
					$(this).parents('.left-con').next().children().find('.ingr-info').hide();
					$(this).parents('.left-con').next().children().find('.nutr-info').show();
					
					$(this).parents('.left-con').next().children().find('.scroll-pane3').jScrollPane({showArrows: true});
					
					
				});
				$('h2.prod').click(function(){
					$(this).removeClass('active');
					$(this).parents('.left-con').find('.ingr').removeClass('ingr-act');
					$(this).parents('.left-con').find('.nutr').removeClass('nutr-act');
					$(this).parents('.left-con').next().children().find('.ingr-info').hide();
					$(this).parents('.left-con').next().children().find('.nutr-info').hide();
					$(this).parents('.left-con').next().children().find('.prod-info').show();;
					
				});
			},
			preLoaderImg:function()
				{
				
					var _govar=false;
					var t;
					for (var i = 0; i < document.images.length; i++) 
					{
						var image_obj = new Image(); // create an image object
						image_obj.src = document.images[i].src;
							if(!document.images[i].complete)
								{
									$("#prodLoadingGraphic").show();
									t=setTimeout("klondike.ui.preLoaderImg()",100);
									return false;
													
								} else {$("#prodLoadingGraphic").hide()}
								
					}
					clearTimeout(t);
					klondike.ui.carousel();
					
				},
			carousel: function()
				{
				if($('body').hasClass('products')) {
							
					
					var _timtWdt=new Array();
					var _counter=0;
						$("#mycarousel li").each(function(){
							$(this).children().children().eq(0).removeClass("none");
							var _imgWdt=$(this).children().children().eq(0).attr('width');
							_timtWdt[_counter] = _imgWdt;
							_counter++;
							$(this).css('width', _imgWdt + "px");
							if($(this).hasClass("last")){
								$(this).css('width', _imgWdt+30 + "px");
							}
								
						});
						var nw_timtWdt=0;
						var fnl_prntWdt=0;
						for (var i = 0; i < _timtWdt.length; i++) {
							nw_timtWdt=nw_timtWdt+_timtWdt[i]+30;
							if(nw_timtWdt<733) {
								fnl_prntWdt=nw_timtWdt;
							}
						}
						jQuery('#mycarousel').jcarousel({
						initCallback: function() {
						if(nw_timtWdt<"733") {
							$('.jcarousel-clip-horizontal').css('width', nw_timtWdt+30 +"px")
							$('.jcarousel-clip-horizontal li.last').css('margin-right', 0 +"px");
							$('.jcarousel-clip-horizontal li.first').css('margin-left', 30 +"px");
							} 
							
						if(nw_timtWdt>"733") {$('.jcarousel-clip-horizontal').css({"width":fnl_prntWdt+"px"}); }
						}
						});
						
						
						$('#mycarousel li a img').css('position','absolute');
						$("#mycarousel li a").hover(function(){$(this).children().eq(0).hide(); $(this).children().eq(1).show();
							if(!$(this).parent().hasClass("first")) {
								 $(this).children().eq(1).css('margin-left','-9px');
							}
						},function(){$(this).children().eq(0).show();$(this).children().eq(1).hide()});
					
					
				}
				
				 else {return false}
				},
				popup: function()
					{			
						
						if ($('body *').hasClass('popup-coupon')) {
						$(".popup-coupon a").colorbox({iframe:true, innerWidth:915, innerHeight:440})
						}
								
					}
		

		
	};
	
$(document).ready(function(){
	klondike.ui.init();

});

