function NavigateThrough(event){
	if(!document.getElementById)return;
	if(window.event)
		event=window.event;
	if(event.ctrlKey){
		var link=null;
		var href=null;
		switch(event.keyCode?event.keyCode:event.which?event.which:null){
			case 0x25:link=document.getElementById('PrevPage');break;
			case 0x27:link=document.getElementById('NextPage');break;
			case 0x26:
		}
		if(link&&link.href)
			document.location=link.href;
		if(href)
			document.location=href;
	}
}

function GetNYGoods(){
	$.post('/ny_goods.php',"{}",function(data){
		$('#ny_goods').fadeOut(500,function(){
			$('#nyg_a').attr('title',data.name);
			$('#nyg_a').attr('href',data.itemhref);
			$('#nyg_img').attr('alt',data.name);
			$('#nyg_img').attr('src',data.src);
			$('#nyg_price').text(data.price);
			$('#ny_goods').fadeIn(500);
		});			
	},'json');
}
 
function SetNYGoodsTimer(){
	if(!document.getElementById)return;
	var div=document.getElementById('ny_goods');
	if (div) window.setInterval("GetNYGoods();",15000);
}

function GetBanner(){
	var id = $('#sitebar_left_banner span').attr('id').substring(1,100);
	$.post('/ajax.php?action=ban&banid='+id,"{}",function(data){
		$('#sitebar_left_banner').fadeOut(500,function(){
			$('#sitebar_left_banner').attr('href',data.href);
			$('#sitebar_left_banner span').attr('id',data.id);
			$('#sitebar_left_banner img').attr('alt',data.title);
			$('#sitebar_left_banner img').attr('src',data.src);
			$('#sitebar_left_banner').fadeIn(500);
		});			
	},'json');
}

function SetBannerTimer(){
	if(!document.getElementById)return;
	var div=document.getElementById('sitebar_left_banner');
	if (div) window.setInterval("GetBanner();",8000);
}

function AddOptionToSelect(selobj,text,value,isselected)
{
	selobj.options[selobj.options.length] = new Option(text,value,false,isselected);
}

function opaqalize() {
	$("embed").attr("wmode", "opaque");
	var embedTag;
	$("embed").each(function(i) {
		   embedTag = $(this).attr("outerHTML");
		   if ((embedTag != null) && (embedTag.length > 0)) {
				   embedTag = embedTag.replace(/embed /gi, 'embed wmode="opaque" ');
				   $(this).attr("outerHTML", embedTag);
		   } else {
				   $(this).wrap("<div></div>");
		   }
	});
}
 
$(document).ready(function(){
	document.onkeydown=NavigateThrough;
	
	$("a.lvl").click(function(){
		$(this).parent().next("div").toggle("middle");
		return false;
	});

	$(document).click(function(){
		$(".hc_menu").slideUp("fast");
	});

	$("#m_for_her").click(function(){
		$("#hc_menu_her .shadow_l").height($("#hc_menu_her").height());
		$("#hc_menu_her .shadow_r").height($("#hc_menu_her").height());
		$(".hc_menu").slideUp("fast");
		$("#hc_menu_her").slideDown("fast");
		return false;
	});

	$(".submenu").click(function(){
		$(this).next("div.hc_submenu").children(".shadow_l").height($(this).next("div.hc_submenu").height());
		$(this).next("div.hc_submenu").children(".shadow_r").height($(this).next("div.hc_submenu").height());
		$(this).next("div.hc_submenu").css("top",$(this).position().top+"px");
		$(this).next("div.hc_submenu").slideDown("fast");
		return false;
	});

	$("#m_for_him").click(function(){
		$("#hc_menu_him .shadow_l").height($("#hc_menu_him").height());
		$("#hc_menu_him .shadow_r").height($("#hc_menu_him").height());
		$(".hc_menu").slideUp("fast");
		$("#hc_menu_him").slideDown("fast");
		return false;
	});

	$("#m_for_holiday").click(function(){
		$("#hc_menu_holiday .shadow_l").height($("#hc_menu_holiday").height());
		$("#hc_menu_holiday .shadow_r").height($("#hc_menu_holiday").height());
		$(".hc_menu").slideUp("fast");
		$("#hc_menu_holiday").slideDown("fast");
		return false;
	});

	$("#arrow_left").hover(
		function(){
			$("#arrow_left").attr("src","/images/common/arrow-left-h.gif");
		},function(){
			$("#arrow_left").attr("src","/images/common/arrow-left.gif");
		}
	);
	$("#arrow_right").hover(
		function(){
			$("#arrow_right").attr("src","/images/common/arrow-right-h.gif");
		},function(){
			$("#arrow_right").attr("src","/images/common/arrow-right.gif");
		}
	);
	
	$(".add_to_basket").hover(function(){
		$(this).css('background-position','0 -22px');
	},function(){
		$(this).css('background-position','0 0');
	});
	$(".add_to_basket").mousedown(function(){
		$(this).css('background-position','0 -44px');
	});
	$(".add_to_basket").mouseup(function(){
		$(this).css('background-position','0 -22px');
	});

	var scrol = $("#collections").scrollable( {circular:true,onBeforeSeek:function(e,i){
		var items = this.getItems().eq(i);
		items.find("img").each(function(){ 
			if ($(this).attr("alt") != ""){
				$(this).attr("src",$(this).attr("alt"));
				$(this).attr("alt","");
			}
		});
	}} );
	
	SetNYGoodsTimer();
	SetBannerTimer();
	opaqalize();
});

