function BuildPositions(mode, id){
	if(mode == 'yandex'){
		var html = "";
		jQuery.get("/proxy.php", {url:'http://seo.kinetica.su/api/position~yandex/'+id}, function(data){		
			var data = data.contents;
			if(data.list.length > 0){
			
				html += "<table>";
				html += "<tr><th class='title'><a href='http://"+data.url+"' target='_blank'>"+data.url+"</a></th><th class='yandex' align='center'><div></div></th></tr>";
				
				for(var i in data.list){
					var item = data.list[i];
					if(item){
						html += "<tr><td class='title'>"+item.title+"</td><td class='position'><a href='"+item.url+"' target='_blank'>"+item.position+" место</a></td></tr>";
					}
				}
				
				html += "</table>";
				html += "<div class='visits'><label>Посещаемость:</label><div>"+data.visits+"<span>месяц</span></div></div>";
				
				jQuery("#keywords div.list").html(html).children("table").hide().show(300);
				
			}else{
				jQuery("#keywords").remove();
			}
		});
	}
}


var Imageline = {
	total: 0,
	cursor: 0,
	init: function(){
		this.total = jQuery("#imageline > div > ul > li").length;
		this.render();
		if(jQuery("#imageview").length){
			var html = "";
			jQuery("#imageline > div > ul > li").each(function(key, item){		
				var href = jQuery(item).find("a").attr("href");
				html += "<img src='"+href+"'>";			
			});
			jQuery("#imageview").html(html);
			jQuery("#imageview img").hide();
			jQuery("#imageview img:eq(0)").addClass("active").show();
			var href = jQuery("#imageline > div > ul > li").eq(0).find("a").attr("href");			
		}
	},
	go: function(direction){
		if(direction > 0){
			if(this.cursor >= this.total-3) return false;
		}else{
			if(this.cursor < 1) return false;
		}
		this.cursor += direction;
		this.render();
	},
	render: function(){
		if(this.cursor < 1) jQuery("#imageline > a.prev").fadeOut(300); else jQuery("#imageline > a.prev").fadeIn(300);
		if(this.cursor >= this.total-3) jQuery("#imageline > a.next").fadeOut(300); else jQuery("#imageline > a.next").fadeIn(300);
		jQuery("#imageline > div > ul").animate({marginLeft: -(this.cursor*219)+"px"}, 300);
	},
	view: function(href){
		var item = jQuery("#imageview img[src='"+href+"']");
		if(!jQuery(item).hasClass("active")){
			jQuery("#imageview img").removeClass("active").fadeOut();
			jQuery("#imageview").animate({height: jQuery(item).height()+"px"}, 300);
			jQuery(item).addClass("active").fadeIn(300);
		}
		
	}
};

var magicId = 0;
var Worklist = {
	iwidth: 200,
	cursor: 0,
	offsetLeft: 0,
	total: 0,
	llimit: 0,
	rlimit: 0,
	limit: 3,
	init: function(){
		this.total = jQuery("#worklist li").length;
		this.rlimit = this.total*2-1;
		this.llimit = this.total;
		this.offsetLeft = (-this.total*this.iwidth) + this.iwidth;
		jQuery("#worklist ul").css({marginLeft: this.offsetLeft+"px"});
		jQuery("#worklist li").clone().addClass("clone").appendTo("#worklist ul").clone().addClass("clone").prependTo("#worklist ul");

		var hash = document.location.hash.substring(1);
		if(hash) magicId = hash;
		if(magicId){
			this.cursor = jQuery("#worklist li[rel="+magicId+"]").index();
		}
		this.render();
	},
	prev: function(){
		this.cursor--;	
		if(this.cursor <= -this.llimit){ 
			this.llimit += this.total;
			this.offsetLeft -= (this.total)*this.iwidth;
			jQuery("#worklist ul").stop().css({marginLeft: this.offsetLeft+(this.iwidth*-this.cursor)-this.iwidth+"px"});
			jQuery("#worklist ul li").not('.clone').clone().addClass("clone").prependTo("#worklist ul");
		}
		this.render();
	},
	next: function(){
		this.cursor++;
		if(this.cursor >= this.rlimit){ 
			this.rlimit += this.total;
			jQuery("#worklist ul li").not('.clone').clone().addClass("clone").appendTo("#worklist ul");	
		}
		this.render();
	},
	render: function(){
		jQuery("#worklist ul li.active").find("img").stop().animate({width:"140px",marginTop:"13px"}, 300).removeClass('active');
		var citem = jQuery("#worklist ul li").eq(this.llimit-(this.cursor*-1)).addClass('active');
		var id = jQuery(citem).attr("rel");
		jQuery(citem).find("img").stop().animate({width:"170px",marginTop:0}, 300);
		jQuery("#worklist ul").width(this.iwidth*(this.llimit+this.rlimit+this.total)+1000).stop().animate({marginLeft: (this.offsetLeft+(this.iwidth*-this.cursor))+"px"}, 300);
		
		jQuery("#workview > h2 span.title").text(jQuery("div.title",citem).text());
		jQuery("#workview > h2 span.loading").css("visibility", "visible");
		jQuery("#workview > div.content").slideUp(300);
		//jQuery("#workview-l").fadeOut(300);
		document.location.hash = id;
		jQuery.post("/workview", {id:id}, function(data){
			jQuery("#workview > h2 span.loading").css("visibility", "hidden");
			jQuery("#workview > div.content").html(data);
			jQuery("#workview-l").empty().append(jQuery("#workview > div.content div.left-content"));//.fadeIn(300);
			jQuery("#workview > div.content").slideDown(300);
			Imageline.init();
		});
		
	}
};


			var goldensite_stun = false;		
			var Goldensite = {
				total: 0,
				cursor: 0,
				init: function(){
					this.total = jQuery("#goldensite_view > div").length;
					this.render();
				},
				go: function(direction){
					if(direction > 0){
						if(this.cursor >= this.total-4) return false;
					}else{
						if(this.cursor < 1) return false;
					}
					this.cursor += direction;
					this.render();
				},
				render: function(){
					if(this.cursor < 1) jQuery("#goldensite > a.prev").fadeOut(300); else jQuery("#goldensite > a.prev").fadeIn(300);
					if(this.cursor >= this.total-4) jQuery("#goldensite > a.next").fadeOut(300); else jQuery("#goldensite > a.next").fadeIn(300);
					jQuery("#goldensite div.list > div").animate({marginLeft: -(this.cursor*160)+"px"}, 300);
				}
			};
			
jQuery(function(){

	jQuery("#goldensite div.list div.item > a").bind("click", function(){
		if(goldensite_stun){
			goldensite_stun = false;
			jQuery("#goldensite div.list div.item").animate({opacity:1}, 300);
			jQuery("#goldensite_view div.view").fadeOut(300);
			return false;
		}
		goldensite_stun = true;
		var id = jQuery(this).closest("div.item").attr("rel");
		jQuery("#goldensite div.list div.item").animate({opacity:0.3}, 300);
		jQuery("#goldensite_view div.view[rel="+id+"]").fadeIn(300);
		return false;
	});
	jQuery("#goldensite_view div.view a.close").bind("click", function(){
		goldensite_stun = false;
		jQuery("#goldensite div.list div.item").animate({opacity:1}, 300);
		jQuery(this).closest("div.view").fadeOut(300);
		return false;
	});
	
	jQuery("#goldensite > a.prev").bind("click", function(){
		Goldensite.go(-1);
	});
	
	jQuery("#goldensite > a.next").bind("click", function(){
		Goldensite.go(1);
	});


	if(jQuery("#imageline").length){
		Imageline.init();
	}
	
	if(jQuery("#worklist").length){
		Worklist.init();
		
		jQuery("#worklist > a.prev").bind("click", function(){
			Worklist.prev();
			return false;
		});
		jQuery("#worklist > a.next").bind("click", function(){
			Worklist.next();
			return false;
		});
		
	}
	
	if(jQuery("#maps").length){
		var jquery_maps = jQuery("#maps");
			jQuery("ul.view > li.index > a", jquery_maps).
			add("ul.content > li > div.title > a", jquery_maps).
			bind("click", function(){	
				var id = jQuery(this).attr("rel");	
				jQuery("ul.view li", jquery_maps).hide();
				jQuery("ul.view li[rel="+id+"]", jquery_maps).show();
				jQuery("ul.content").fadeIn(300);
				jQuery("ul.content li", jquery_maps).removeClass("active");
				jQuery("ul.content li[rel="+id+"]", jquery_maps).addClass("active");
			});
			
	
		var hash = document.location.hash.substring(1);	
		if(hash) jQuery("#maps ul.content > li[rel="+hash+"] > div.title > a").click();
	}
	
	
	
	
	jQuery("#mediacontent li a").click(function(){
		jQuery("#mediacontent li").fadeIn(300);
		jQuery(this).parent().fadeOut(300);
		return false;
	});
	
	
	jQuery("#content div.benefits > div.list > div.item > a").bind("click", function(){
		if(!jQuery(this).hasClass("active")){
			jQuery("#content div.benefits > div.list > div.item > a").removeClass("active");
			jQuery("#content div.benefits > div.list > div.view").fadeOut(300);
			var id = jQuery(this).addClass("active").parent().attr("rel");
			jQuery("#content div.benefits > div.list > div.view[rel="+id+"]").fadeIn(300);
		}
		return false;
	});
	
	jQuery("#content div.benefits > div.list > div.view a.close").bind("click", function(){
		jQuery("#content div.benefits > div.list > div.item > a").removeClass("active");
		jQuery("#content div.benefits > div.list > div.view").fadeOut(300);
		return false;
	});
    
    jQuery("#pricelist").click(function(){
        _gaq.push(['_trackEvent', 'file', 'download', 'pricelist']);
        yaCounter1280665.reachGoal("kinprice");
    });
	
	
	
	jQuery("#order a").bind("click", function(){
		var pos = jQuery(this).position();
		jQuery("#orderform").css({left:(pos.left+180)+"px", top:(jQuery(document).scrollTop()+120)+"px"}).fadeIn(300);
		return false;
	});
	jQuery("#orderform a.close").bind("click", function(){
		jQuery("#orderform").fadeOut(300);
		return false;
	});
	
	jQuery("#orderform form").bind('submit', function(){
		if(jQuery(this).data('freez')) return false;
		if(orderform_event) _gaq.push(['_trackEvent', 'orderForm', 'submit', orderform_event]);
		jQuery(this).data('freez', true);
		var form = jQuery(this);
		jQuery('#orderform').animate({opacity:0.3},300);
		jQuery(this).ajaxSubmit({
			url: '/udata/webforms/send_ajax',
			success: function(src){	
				if(src == 'success'){
					alert('Ваша заявка принята');
					jQuery(form).resetForm();
					if(orderform_event == 'morda'){
						jQuery('#orderform').stop().animate({opacity:1},300);
					}else{
						jQuery("#orderform").fadeOut(300, function(){
							jQuery("#orderform").css({opacity:1});
						});				
					}
				}else{
					alert(src);
					jQuery('#orderform').stop().animate({opacity:1},300);
				}	
				jQuery(form).data('freez', false);
			}
		});
		return false;
	});
	

	
	/*
	jQuery("#orderform form").bind("submit", function(){
		if(jQuery(this).data("stun")) return false;
		jQuery(this).data("stun", true);
		jQuery(this).ajaxSend({ 
			success: function(src){ 
				if(src == 'success'){
					alert('Ваша заявка принята');
					jQuery("#orderform").fadeOut(300);
				}else{
					alert(src);
				}	
				jQuery("#orderform form").data("stun", false);
			}
		});
		return false;
	});
	*/
	/*
	jQuery("#orderform form").bind("submit", function(){
		if(jQuery(this).data("stun")) return false;
		jQuery(this).data("stun", true);
		jQuery.post("/udata/webforms/send_ajax", jQuery(this).serialize(), function(src){
			if(src == 'success'){
				alert('Ваша заявка принята');
				jQuery("#orderform").fadeOut(300);
			}else{
				alert(src);
			}	
			jQuery("#orderform form").data("stun", false);
		});
		return false;
	});
	*/
	
	
	jQuery("#footer a.brocket").bind("click", function(){
		var pos = jQuery(this).position();
		jQuery("#brocket").fadeIn(300);
		return false;
	});
	jQuery("#brocket a.close").bind("click", function(){
		jQuery("#brocket").fadeOut(300);
		return false;
	});
	
	
	jQuery("a.toggle_bw_img").bind('mouseover', function(){
		jQuery(this).children().attr('src', jQuery(this).attr('img'));
	});
	
	jQuery("a.toggle_bw_img").bind('mouseout', function(){
		jQuery(this).children().attr('src', jQuery(this).attr('bw'));
	});
	
	
	
	jQuery("#seocase.toggle").bind("mouseenter", function(){
		jQuery(this).stop().animate({height:jQuery(this).children('ul').height()+'px'}, 300);
		if(jQuery.browser.msie){
			jQuery('> div.overlay',this).hide();
		}else{
			jQuery('> div.overlay',this).stop().animate({opacity:0}, 300, function(){
				jQuery(this).hide();
			});
		}

	});
	
	jQuery("#seocase.toggle").bind("mouseleave", function(){
		jQuery(this).stop().animate({height:'50px'}, 300);
		if(jQuery.browser.msie){
			jQuery('> div.overlay',this).show();
		}else{
			jQuery('> div.overlay',this).stop().show().animate({opacity:1}, 300);
		}
		
	});
	
	
	$('#fotarr').bind('click', function(){
		if($(this).data('lock')) return false;
		var button = $(this).data('lock', true);
		var current = $('#fotlist > li:visible').eq(0);
		var next = current.hide(300).next();
		if(!next.length) next = $('#fotlist > li').eq(0);
		next.show(300, function(){
			button.data('lock', false);
		});
		return false;
	});
	
});

jQuery("#imageline > a.prev").live("click", function(){
	Imageline.go(-1);
	return false;
});
jQuery("#imageline > a.next").live("click", function(){
	Imageline.go(1);
	return false;
});
jQuery("#imageline > div > ul > li a.imageview").live("click", function(){
	var href = jQuery(this).attr("href")
	Imageline.view(href);
	return false
});

