$(document).ready(function(){
	var path = document.location.pathname;		
	if ( path.charAt(path.length-1) != '/' ) path = path+'/';
	var epos = document.location.pathname.indexOf('/',1) == -1 ? document.location.pathname.length : document.location.pathname.indexOf('/',1)-1;
	var section = document.location.pathname.substr(1, epos );
	
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}
	
	// FONTS -------------------------------------------------------------------
	Cufon.replace('.title-js').replace('h3').replace('h4');
	
	if ($.browser.msie && $.browser.version == 6) {
		$("#product-block div.items").hover(function(){
			$(this).css({
				"background-position": "0px -65px",
				"z-index": "15"
			});
			$(".listMenu", this).show();
		}, function(){
			$(this).css({
				"background-position": "0px 0px",
				"z-index": "10"
			});
			$(".listMenu", this).hide();
		});
	}
	
	
	
	function addActiveMenu(){
		$("#menu a[href='/" + section + "/']").addClass("active");
		if (section != '') {
			var idx = $("#menu div").index($("#menu a[href='/" + section + "/']").parent());
			if (idx > 0) {
				$("#menu div").eq(idx).addClass("active");
				$("#menu div").eq(idx - 1).addClass("left_active");
				$("#menu div").eq(idx + 1).addClass("right_active");
				$("#menu div").eq(idx - 1).removeClass("separator");
				$("#menu div").eq(idx + 1).removeClass("separator");
			}
			//alert(section);
			if(section == 'services')
				$("#menu div").eq(3).addClass("left_active");
		}
	}
	addActiveMenu();
	
	$("#services").hover(function(){
		$(this).addClass("hover");
		$("#services a").addClass("active");
		
		$("#services .left").addClass("left_hover");
		$("#services .right").addClass("right_hover");
	}, function(){
	
		$("#services .left").removeClass("left_hover");
		$("#services .right").removeClass("right_hover");
		$(this).removeClass("hover");
		$("#services a").removeClass("active");
		
		addActiveMenu();
		
	});
	
	
	
	
	var max_img = parseInt( $("#pic_count").val() );
	var next_id;
	$("#next-button").mousedown(function(){
		var margin = parseInt( $("#pic-line").css("margin-left") );
		$(this).addClass("active");
		next_id = setInterval(function() {
			margin = parseInt( $("#pic-images div").css("margin-left") );
			if( margin == -(max_img * 2 * 190) ) {
				margin = -(max_img * 190);
				$("#pic-line").css("margin-left", margin + 'px');
			}
			$("#pic-line").css("margin-left", (margin - 5) + 'px');
			//$("#info-block").html(margin);
		}, 10);
    }).mouseup(function(){
		$(this).removeClass("active");
		clearInterval(next_id);
    }).mouseout(function(){
		$(this).removeClass("active");
		clearInterval(next_id);
    });

	var prev_id;
	$("#preview-button").mousedown(function(){
		var margin = parseInt( $("#pic-line").css("margin-left") );
		$(this).addClass("active");
		prev_id = setInterval(function() {
			margin = parseInt( $("#pic-images div").css("margin-left") );
			if( margin == 0 ) {
				margin = -(max_img * 190);
				$("#pic-line").css("margin-left", margin + 'px');
			}
			$("#pic-line").css("margin-left", (margin + 5) + 'px');
			//$("#info-block").html(margin);
		}, 10);
    }).mouseup(function(){
		$(this).removeClass("active");
		clearInterval(prev_id);
    }).mouseout(function(){
		$(this).removeClass("active");
		clearInterval(prev_id);
    });
	
	
	
	
	// TABLE --------------------------------------------
	$("table.js-table th").each(function(){
		$(this).html("<span>" + $(this).html() + "</span>");
	});
	$("table.js-table th.th-center, table.js-table th.th-left, table.js-table th.th-right").each(function(){
		$(this).html("<div class=\"border-left\"><div class=\"border-right\">" +
		$(this).html() +
		"</div></div>");
	});
	$("table.js-table tr th:last").css({"border-right" : "0px"});
	$("table.js-table tr th:first").css({"border-left" : "0px"});
	
	
	
});
