// JavaScript Document
jQuery(document).ready(function() {
	jQuery(function() {
		jQuery(".anyClass").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		itemFallbackDimension:380,
		auto: 3000,
		speed: 1000});
	});
	
	jQuery(function() {
		jQuery(".hometop10").jCarouselLite({
		btnNext: ".nextTop10",
		btnPrev: ".prevTop10",
		itemFallbackDimension:280,
		visible:1,
		auto: 4000,
		speed: 1000});
	});
	
	
	jQuery('a.openinghours').hover(opOver, opOut);
    function opOver(event) {
		jQuery('#openhours').show();
		jQuery('#arrow').attr("src", "/assets/images/newdesign/arrow_down.gif");
		}

	function opOut(event) {
		//jQuery('#openhours').hide();
		jQuery('#arrow').attr("src", "/assets/images/newdesign/arrow_right.gif");
		}		
	
	jQuery('#div_opening_hours').hover(opHoursDivOver, opHoursDivOut);
    function opHoursDivOver(event) {
		jQuery('#openhours').show();
		jQuery('#arrow').attr("src", "/assets/images/newdesign/arrow_down.gif");
		}

	function opHoursDivOut(event) {
		jQuery('#openhours').hide();
		jQuery('#arrow').attr("src", "/assets/images/newdesign/arrow_right.gif");
		}		
		
		
		
	jQuery('a.title').cluetip({splitTitle: '|',tracking: true});    
	if ((!jQuery.browser.msie)) { // IE corner has issue 
		jQuery('.advertcontainer').corner();
	}

});

jQuery(document).ready(function() {
	//jQuery('.homepage_middle_box_types').hide();	
	jQuery('.productlink_intro').hide(); 
	jQuery('.homepage_middle_box_offers').hide();
	jQuery('#homepage_box_static').show();
	jQuery('.menu_sub_text').hide();
	jQuery("#offers_vital").show();
	//jQuery("#types_main").show();	
	//Load the slideshow
	var rotatorId = '1';
	var intval = "";
	var menuTextId = '1';
	
	//$('div.rotator'+rotatorId+'').fadeIn(1000);
	if ( jQuery.browser.msie ) {
    	jQuery('div.rotator'+rotatorId+' ul li').fadeOut(); // tweek for IE
		jQuery('div.rotator'+rotatorId+' ul li:first').fadeIn();
		jQuery('div.sliderpages ul li').fadeIn();
		jQuery('.menu_sub_text').fadeOut();
	}
	//else
	//{
		//Set the opacity of all images to 0
		jQuery('div.rotator'+rotatorId+' ul li').css({opacity: 0.0});
		jQuery('div.sliderpages ul li').css({opacity: 1.0});
		//Get the first image and display it (gets set to full opacity)
		jQuery('div.rotator'+rotatorId+' ul li:first').css({opacity: 1.0});
		//Call the rotator function to run the slideshow, 5000 = change to next image after 5 seconds
	//}
	intval = setInterval('rotate('+rotatorId+')',5000);
	
	
	jQuery('div.sliderpages ul li').hover(overpage, outpage);
    function overpage(event) {
			var id  = this.id
		  	window.clearInterval(intval);
			var rel = this.getAttribute('rel');
			jQuery('div.sliderpages ul li').removeClass('pageselected'); 

			if ( jQuery.browser.msie ) {jQuery('div.rotator'+rotatorId+' ul li.show').fadeOut();}
			else
			{
				jQuery('div.rotator'+rotatorId+' ul li.show').animate({opacity: 0.0}, 1000); 
			}
			jQuery('div.rotator'+rotatorId+' ul li.show').removeClass('show')
			//this
			jQuery('div.sliderpages ul li:nth-child('+rel+')').addClass('pageselected');
			//alert($('div.rotator'+rotatorId+' ul li:nth-child('+rel+')').html());
			if (jQuery.browser.msie ) {jQuery('div.rotator'+rotatorId+' ul li:nth-child('+rel+')').fadeIn();
			jQuery('div.rotator'+rotatorId+' ul li:nth-child('+rel+')').addClass('show');
			}
			else
			{
				jQuery('div.rotator'+rotatorId+' ul li:nth-child('+rel+')').css({opacity: 0.0})
														 .addClass('show')
														 .animate({opacity: 1.0}, 0);
			}
			jQuery('div.sliderpages ul li').removeClass('show'); 
			
			
		}
	function outpage(event) {
		var id  = this.id;
        	//setInterval('rotate('+rotatorId+')',4000);
		}
		
	jQuery('div.rotator'+rotatorId+' ul').hover(overme, outme);
    function overme(event) {
		var id  = this.id
		  	window.clearInterval(intval)
		}
	function outme(event) {
		var id  = this.id;
        	intval = setInterval('rotate('+rotatorId+')',5000);
		}
		
	jQuery('.openlink').hover(over, out);
    function over(event) {
		var id  = this.id
		
		//jQuery('.homepage_middle_box_types').hide();    
		jQuery('.productlink_intro').hide();
		jQuery('.homepage_middle_box_offers').hide();
		jQuery('#homepage_box_static').show();
		jQuery("#offers_vital").hide();
		//jQuery("#types_main").hide();

		jQuery("#" + id).removeClass("white");
		
		//jQuery("#prod_" + id).fadeIn(1000); 
		//jQuery("#types_" + id).fadeIn(1000);
		jQuery('div#menu_sub_text'+menuTextId+'').fadeOut();
		jQuery('#main_navigations a').css('color','#ffffff');
		//$('div#main_nav'+menuTextId+' a').css('color','#ffffff');
		menuTextId = this.getAttribute('rel');
		jQuery('div#main_nav'+menuTextId+' a').css('color','#990000');
		jQuery('div#menu_sub_text'+menuTextId+'').fadeIn();
		 
		jQuery("#offers_" + id).fadeIn(1000); 

		 /*if(intval!=""){
		  	window.clearInterval(intval)
          	intval=""
		  	$('div.rotator'+rotatorId+'').fadeIn(1000);
			$('div.rotator'+rotatorId+' ul li').fadeIn(1000); // tweek for IE
			$('div.rotator'+rotatorId+' ul li').css({opacity: 0.0});
			$('div.rotator'+rotatorId+' ul li:first').css({opacity: 1.0});
			intval = setInterval('rotate('+rotatorId+')',4000);
		 }*/
		  
		 
	
		}
	function out(event) {
		var id  = this.id;
			//if(menuTextId == this.getAttribute('rel')) { jQuery('.menu_sub_text').hide();}
		// return false to prevent the anchor tag from following the href rule
		return false;
		}
});

function theRotator(rotatorId) {
	
	
}

function rotate(rotatorId) {	
	//Get the first image
	var current = (jQuery('div.rotator'+rotatorId+' ul li.show')?  jQuery('div.rotator'+rotatorId+' ul li.show') : jQuery('div.rotator'+rotatorId+' ul li:first'));
	var currentPage = (jQuery('div.sliderpages ul li.pageselected')?  jQuery('div.sliderpages ul li.pageselected') : jQuery('div.sliderpages ul li:first'));
	//var currentPage = $('div#spage'+rotatorId+'')
	
    if ( current.length == 0 ) current = jQuery('div.rotator'+rotatorId+' ul li:first');
    if ( currentPage.length == 0 ) currentPage = jQuery('div.sliderpages ul li:first');
    
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div.rotator'+rotatorId+' ul li:first') :current.next()) : jQuery('div.rotator'+rotatorId+' ul li:first'));
	var nextPage = ((currentPage.next().length) ? ((currentPage.next().hasClass('pageselected')) ? jQuery('div.sliderpages ul li:first') :currentPage.next()) : jQuery('div.sliderpages ul li:first'));
	
	//var nextPage = ((currentPage.next().length) ? ((currentPage.next().hasClass('pageselected')) ? $('div.sliderpage:first') :currentPage.next()) : $('div.sliderpage:first'));
	
//	alert(rotatorId);
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	if ( jQuery.browser.msie ) { 
		next.fadeIn();
		next.addClass('show');
	}
	else
	{
		next.css({opacity: 0.0})
		.addClass('show')
		.animate({opacity: 1.0}, 1000);
	}
	
	nextPage.addClass('pageselected')

	//nextPage.addClass('pageselected');*/

	//Hide the current image
	if ( jQuery.browser.msie ) {
		current.fadeOut();
		current.removeClass('show');
		}
		else
		{
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
		}
	currentPage.removeClass('pageselected');
	
	//currentPage.removeClass('pageselected');
};
