
 $j(function() {
	  
		//cache the ticker
		var ticker = $j("#ticker");
		  
		//wrap dt:dd pairs in divs
		ticker.children().filter("dd").each(function() {
		  
		  var dt = $j(this),
		    container = $j("<div>");
		  
		  dt.next().appendTo(container);
		  dt.prependTo(container);
		  
		  container.appendTo(ticker);
		});
				
		//hide the scrollbar
		ticker.css("overflow", "hidden");
		
		//animator function
		function animator(currentItem) {
		    
		  //work out new anim duration
		  var distance = currentItem.height();
			duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.045;

		  //animate the first child of the ticker
		  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
		    
			//move current item to the bottom
			currentItem.appendTo(currentItem.parent()).css("marginTop", 0);

			//recurse
			animator(currentItem.parent().children(":first"));
		  }); 
		};
		
		//start the ticker
		animator(ticker.children(":first"));
				
		//set mouseenter
		ticker.mouseenter(function() {
		  
		  //stop current animation
		  ticker.children().stop();
		  
		});
		
		//set mouseleave
		ticker.mouseleave(function() {
		          
          //resume animation
		  animator(ticker.children(":first"));
		  
		});
	  });  
$j(document).ready(function() {
	
		var tmfad;
		/* categories */
		$j('.left-categories-op').bind('mouseenter mouseover',function() {		
			
			var a = $j(this);
			$j('.left-categories-subs').unbind('mouseleave');
			$j('.left-categories-op').unbind('mouseleave');
			$j('.left-categories-subs').fadeOut();
			$j('.left-categories-op').removeClass('left-categories-op-hov');			
			clearTimeout(tmfad);			
			var id = $j(this).attr('rel');		
			var cat = $j('#categories-'+id);				
			if(cat.length > 0) {
				
				//get viewport
				var wh = $j(window).height() + $j(window).scrollTop();
				var eh = cat.height();
				var pos = a.position();
				var et = pos.top;
				var etot = eh + et;
				if(etot > wh) {
					cat.css('top',(et-(etot-wh))+'px');
				}								
				
				tmfad = setTimeout(function() {	
					$j('#categories-'+id).fadeIn().bind('mouseenter mousemove',function() {		
						clearTimeout(tmfad);				
						$j(this).show();						
						a.addClass('left-categories-op-hov');
					});
				},200);
			}	
		});		
		
		$j('.left-categories-op').bind('mouseleave mouseout',function() {	
			clearTimeout(tmfad);				
			$j('.left-categories-subs').bind('mouseleave',function() {
				tmfad =	setTimeout(function() { $j('.left-categories-subs').fadeOut()},500);
				$j(this).removeClass('left-categories-op-hov');	
				$j('.left-categories-op').removeClass('left-categories-op-hov');	
				return;
			});	
			
			tmfad =	setTimeout(function() { $j('.left-categories-subs').fadeOut()},500);
			$j(this).removeClass('left-categories-op-hov');	
			$j('.left-categories-op').removeClass('left-categories-op-hov');
			
		});

		
		// rotator slider
		 $j('.rotator').eq(0).addClass('rot-first');			 
		 $j('.rotator-btn').bind('mouseup',function() {			 
			 switch_what = $j(this).index()-1;
			 
			 switchTo();				 
			 clearInterval(switch_iv);
			 if(switch_to) {
				clearTimeout(switch_to);											
			 }
			 switch_to = setTimeout(function() { startSwitch(switch_what); },2000);
				 
		});
			 
		 var switch_what = 0;
		 var switch_iv;	
		 var switch_to;	
		 
		 function startSwitch() {
			switch_iv = setInterval(function() { switchTo(); },4000)
		 }
			 
		 function switchTo() {
								
			var rot =  $j('.rotator');		
			if(rot.length == 1) return;	
			$j('.rot-on').fadeOut('fast',function() { 
				$j('.rotator').eq(switch_what).fadeIn('fast',function() { $j('.rot-on').removeClass('rot-on'); $j(this).addClass('rot-on')});
				$j('.rotator-btn').removeClass('rotbtn-on');
				$j('.rotator-btn').eq(switch_what).addClass('rotbtn-on');
			});	
								
			switch_what++;	
			if(switch_what == (rot.length)) {
				switch_what = 0;
			}
		 }
			
		 startSwitch();
		 
		 $j('#txt_email_newsletter').bind('mouseup',function() {
			  $j(this).attr('value','');
		 });
		 
		 $j('#cta_email_newsletter').bind('mouseup',function() {
			  estore.newsletter('in'); 
		 });
		 
		
		 
});

		
var estore = {
	newsletter:function(opt) {
		$j.ajax({						  
		   type: "POST",
		   url: "/ajax",
		   data: "action=estore.ajax&func=newsletter&opt="+opt+"&email="+$j('#txt_email_newsletter').val(),
		   
		   success: function(r){
			 alert(r);
			 $j('#txt_email_newsletter').attr('value','');
		   }
	 	});	
		
	},
	
	currencySelector:function() {
		$gcws.alerts({url:'/ajax',action:'estore.ajax',func:'currencies'},'<h2>Currency Selector</h2>','500px','300px');	
	}
}


