// JavaScript Document

var imgs = [
	/* ABONENTAM */
	"/orion-express/main/i/tmp/roundabout_img2.png",	/* center slide */
	"/orion-express/main/i/tmp/roundabout_img3.png",	/* left slide */
	"/orion-express/main/i/tmp/roundabout_img1.png",	/* right slide */
	/* PARTNERAM */
	"/orion-express/main/i/tmp/r_distributoram.png",
	"/orion-express/main/i/tmp/r_operatoram.png",
	"/orion-express/main/i/tmp/r_telekanalam.png",
	/* TELEKANALY */
	"/orion-express/main/i/tmp/r_man.png",
	"/orion-express/main/i/tmp/r_zagorod.png",
	"/orion-express/main/i/tmp/r_uspeh.png"
];

var r_links = [
	/* ABONENTAM */
	"http://www.continent-tv.ru/",
	"http://www.telekarta.tv/",
	"http://vostok.orion-express.ru/",
	/* PARTNERAM */
	"/orion-express/partners/",
	"/orion-express/operators/",
	"/orion-express/channels/",
	/* TELEKANALY */
	"http://www.mans-tv.ru/",
	"http://www.zagorod-tv.ru/",
	"http://www.uspeh-tv.ru/"
];

var w_target = [
	"_blank", "_blank", "_blank",
	"", "", "",
	"_blank", "_blank", "_blank"
];

$(document).ready(function(){

	$('#roundabout ul').roundabout({
		minOpacity: 1,				
		minScale: 0.22,
		duration: 600,
		minZ: 50
	}); 

	var autoplay = 0;
	// autoplay carousel
	//setTimeout( function() { startAutoPlay( autoplay ) }, 1000);
	
	var margin_delta = Math.ceil( ( $(window).height() - $("#top_menu").outerHeight(true) - $("#header").outerHeight(true) - $("#roundabout").outerHeight(true) - $(".footer_wrapper").outerHeight(true) ) / 10 );
	if( margin_delta > 0 ) {
		$(".nav_dots").css("margin-top", margin_delta+"px");
	}

	$('#it1').click(function(e) { 
		nav_act("#dot3");
	});
	$('#it2').click(function(e) { 
		nav_act("#dot2");
	});
	$('#it3').click(function(e) { 
		nav_act("#dot1");
	});
	$('#dot1').click(function(e) {
		e.preventDefault();
		nav_act("#dot1");
		$('#roundabout ul').roundabout_animateToChild(0);	
		return false;
	});
	$('#dot2').click(function(e) {
		e.preventDefault();
		nav_act("#dot2");
		$('#roundabout ul').roundabout_animateToChild(1);
		return false;
	});
	$('#dot3').click(function(e) {
		e.preventDefault();
		nav_act("#dot3");
		$('#roundabout ul').roundabout_animateToChild(2);
		return false;
	});
		
	var delta = 0;
	$("#specials .fixed_width").mousemove( 
		function(e){
			var left_pos = e.pageX - $(this).offset().left;
			if( left_pos <= 319 ) {
				$("#panel .hand").removeClass("is_visible");
				delta = Math.ceil( $("#panel .hand.is_left").width() / 2 );
				if( left_pos - delta <= 0 ) {			
					$("#panel .hand.is_left").css("left", "0px").addClass("is_visible");
				} else {
					$("#panel .hand.is_left").css("left", (left_pos - delta)+"px").addClass("is_visible");
				}
			}
			if( left_pos >= 320 && left_pos <= 656 ) {
				$("#panel .hand").removeClass("is_visible");
				delta = Math.ceil( $("#panel .hand.is_center").width() / 2 );
				$("#panel .hand.is_center").css("left", (left_pos - delta)+"px").addClass("is_visible");
			}
			if( left_pos >= 657 && left_pos <= 862 ) {
				$("#panel .hand").removeClass("is_visible");
				delta = Math.ceil( $("#panel .hand.is_right").width() / 2 );
				$("#panel .hand.is_right").css("left", (left_pos - delta)+"px").addClass("is_visible");
			}
			if( left_pos >= Math.ceil( $("#panel .hand.is_left").width() / 2 ) && left_pos <= 862 ) {
				$("#panel .hand").stop().animate( { left: left_pos - delta }, 1, 'linear', function() { } );
			}
		}
	);
	
	$("#to_abonents").hover( function(){
		$(".special_block").removeClass("act");
		$(this).addClass("act");
		set_attributes(0, 1, 2);
	} );

	$("#to_partners").hover( function(){
		$(".special_block").removeClass("act");
		$(this).addClass("act");
		set_attributes(3, 4, 5);
	} );

	$("#tv_channels").hover( function(){
		$(".special_block").removeClass("act");
		$(this).addClass("act");
		set_attributes(6, 7, 8);
	} );
	
	$("img.r_img").css("width", "576px");
	$("img.r_img").css("height", "441px");
	for( var i = imgs.length - 1; i >= 0; i-- ){
		$("img.r_img").attr("src", imgs[i]);
	}
	$("#it2 img.r_img").attr("src", imgs[1]);
	$("#it1 img.r_img").attr("src", imgs[2]);
	$("img.r_img").css("width", "100%");
	$("img.r_img").css("height", "100%");
});

function set_attributes( index1, index2, index3 ){
	$("#it3 img.r_img").attr("src", imgs[index1]);
	$("#it2 img.r_img").attr("src", imgs[index2]);
	$("#it1 img.r_img").attr("src", imgs[index3]);
	$("#it3 a").attr("href", r_links[index1]);
	$("#it3 a").attr("target", w_target[index1]);
	$("#it2 a").attr("href", r_links[index2]);
	$("#it2 a").attr("target", w_target[index1]);
	$("#it1 a").attr("href", r_links[index3]);
	$("#it1 a").attr("target", w_target[index3]);
}

function nav_act( id ) {
	$(".nav_dots span").removeClass("act");
	$(id).addClass("act");
}

function startAutoPlay( autoplay ) {
	$("#roundabout ul").roundabout_animateToPreviousChild(200);
	setTimeout( function() { $("#roundabout ul").roundabout_animateToPreviousChild(200) }, 300 );
	setTimeout( function() { $("#roundabout ul").roundabout_animateToPreviousChild(200) }, 600 );
}
