var $j = jQuery.noConflict();
var automaticSliderInterval = null;

$j(document).ready( function(){
	// submenu
	$j("#main_menu").superfish({speed		: "fast",
								animation	: {opacity:'show', height:'show'},
								autoArrows	: false,
								dropShadows	: false});
	
	// main page slider
	$j('#main_slider').wslide({
		width		: 556,
		height		: 330,
		horiz		: true,
		duration	: 400,
		autolink	: false
	});
	$j('#right_promo_menu a').click( function(){
		$j('#right_promo_menu a.active').removeClass('active');
		$j(this).addClass('active');

		// reset automatic interval
		clearInterval(automaticSliderInterval);
		automaticSliderInterval = setInterval(automaticSliderAction, 10000);
		
		return false;
	});
	// automatic slider
	automaticSliderInterval = setInterval(automaticSliderAction, 10000);
	
	// end of slider

	// view cart
	$j('#view_cart_header_link').click( function(){
		$j('.cart_header_popup').slideDown(200)
		return false;
	});
	$j('.cart_header_popup a.close-link').click( function(){
		$j('.cart_header_popup').slideUp(200);
		return false;
	});

	// horizontal tabs under main promo - home page
	var prod_list_navi_a = $j('#prod_list_navi a');
	prod_list_navi_a.click( function(){
		prod_list_navi_a.removeClass('active');
		$j(this).addClass('active');
		var index = prod_list_navi_a.index($j(this));

		$j('#prod_list_navi_dest .pln_dest:visible')
			.css('position', 'absolute')
			.hide(0, function(){
				$j(this).css('position', 'static');
			});
		$j('#prod_list_navi_dest .pln_dest').eq(index).show();
		return false;
	});
	// end of horizontal tabs under main promo - home page

	// low-price lightbox
	$j('#lp_1 a, #lp_2 a, #lp_3 a, a.lightbox').fancybox({ ajax : { type : "GET"},
												centerOnScroll	: true,
												scrolling		: 'yes'
												});
});

function automaticSliderAction(){
	var links = $j('#right_promo_menu a');
	var active = links.filter('.active');
	var index = 0;
	
	if(active.length && links.index(active) < links.length - 1){
		index = links.index(active) + 1;
	}
	links.eq(index).click();
}

