// JavaScript Document
$(document).ready(function(){
						   
	// remove this next line for links/anchors to function    or remove noclicks class on anchors
	$('a.noclicks').live('click',function(){ return false; })
	
	// menu
	$('.menu > ul > li').hover(
			function(){
				$(this).addClass('active').next().css('visibility','hidden')
				.end().prev().css('visibility','hidden')
				.end().find('div').css('opacity','0.4').animate({'opacity':'1.0'});
				$(this).find('ul:first').stop(true, true).hide().slideDown()
					.css('opacity','0.9').animate({'opacity':'1.0'});					
			},
			function(){
				$(this).removeClass('active').next().css('visibility','visible')
				.end().prev().css('visibility','visible');
				$(this).find('ul:first').stop(true, true).hide()
						.find('span').css('border-bottom','1px solid #fff');// fix for ie 6...
			}
	); // end menu
	
	// slide show
	if ($('.slideShow').length) {
		$('.slideShow').after('<ul class="slideShow-nav">').cycle({
			fx: 'scrollRight,fade,cover,uncover',
			pager:  '.slideShow-nav',
			sync: true,
			pagerAnchorBuilder: function(idx, slide) {
				return '<li><a href="#">&nbsp;</a></li>';
			}
		});
	}// slide show
	// slide show
	
	/*
	if ($('.cycle-image').length){
		var times = [4500,4400,4500];
		$('.cycle-image').each(function(i){
			var time = times[i];
			$(this).cycle({
				fx: 'scrollRight,fade,cover,uncover',
				timeout: time,
				sync: true
			});
		});
	}
	*/
	
	$(window).bind("resize", methodToFixLayout);
	var winHeight = $(window).height();
	var h = $('.backToTop').height();
	
	function methodToFixLayout( e ) {
		winHeight = $(window).height();
	}
	
	// tabs menu 
	$('.productsHead a').click(function(){
		$('.productsHead > a').each(function(i){
			$(this).removeClass('active').find('img')
				.attr('src','../images/misc/tab'+ (i+1) +'[off].gif')
		})
		var num = $(this).addClass('active').index();
		var img = $(this).find('img');
		img.attr('src','../images/misc/tab'+ (num+1) +'[on].gif')
		return false;
	})
	
	// scroller
	$('.backToTop').css({'margin':'0','top':'445px'})
	$(window).scroll(function()
	{
		var calcHeight = (winHeight/2) - (h/2) + $(window).scrollTop();
		if (calcHeight > 450){
			$('.backToTop').stop().animate({top:calcHeight+"px" },600); 
		} else {
			$('.backToTop').stop().animate({top:"445px" },600); 
		}
		//console.log(winHeight);
	});
	
							/*$('.viewRight .links').jScrollPane({
								showArrows: true,
								scrollbarWidth: 12,
								dragMinHeight: 10,
								dragMaxHeight: 150
							});*/
	
	//fixes
	if ($('.popularTopic').length && $.browser.msie ){
		var el = $('.popularTopic');
		var t = $('.newStore').position().top - 56;
		el.closest('.rightContent').css({'position':'relative'});
		el.css({'position':'absolute','top': t +'px','left':0});
	}
	if (($('.popularTopic').length && $.browser.opera)){
		$('.popularTopic').css({'margin-top':'3px'})
		$('.bestShop .item').css({'margin-top':'11px'})
	}
	if ( $.browser.msie && $.browser.version == '6.0') {
		$('.bestShop .item').css({'margin-top':'6px'})
	}
	if ( $.browser.msie && $.browser.version == '7.0') {
		$('.content .leftContent img.banner01').css({'margin-top':'-16px'});
		$('.menu > ul > li > img').addClass('divider');
		$('.item .view ul, .item .view ul li, .item .view ul li a').css({'display':'block'})
	}
	if ( ! ( $.browser.msie && $.browser.version == '7.0') ) {
		$('.rightContent .products .productsContent').css({'margin-top':'-1px'});
	}
});
