var newsUp = false;
var currentPic = 0;
var picW = 526;

$(document).ready(function(){
	
	/**
	 * Animate Background-position for navigation elements
	 */
	$("#navigation_block a")
	.css({backgroundPosition: "0 0"})
	.mouseover(function(){
		if($(this).hasClass('selected') == false) {
			$(this).stop().animate(
				{backgroundPosition:"(0 -90px)"}, 
				{duration:200})
		}
	})
	.mouseout(function(){
		if($(this).hasClass('selected') == false) {
			$(this).stop().animate(
				{backgroundPosition:"(0 0)"}, 
				{duration:80})
		}
	}) 
	
	if($(".detail").length > 0){
		$("#btn_"+page).addClass("selected").css({backgroundPosition: "0 -90px"});
		
	}
	
	if($("#brandList").length > 0 && brand != ""){
		var btn = $("#btn_"+brand);
		$("#btn_"+brand).addClass("selected");
		btn.parent().addClass("wrapSelected");
	}
	
	if($("#news_block").length > 0){
		$("#news_block").css({
			'bottom':'-80px'
		});
		$("#news_block").click(function(){
			if(newsUp == true){
				var bottomVal = '-80px';
				var durVal = '50';
				newsUp = false;
			}else{
				var bottomVal = '0';
				var durVal = '300';
				newsUp = true;
			}
			$(this).stop().animate(
				{'bottom': bottomVal}, 
				{
					duration: durVal,
					complete: function(){
						$("#news_block dt").toggleClass("min");
					}
				}
			)
		})
	}
	
	
	
	/**
	 * Background-positioning plugin
	 */
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
});