/// <reference path="jquery-1.3.2-vsdoc.js"/>
// JavaScript Document
$(document).ready(function() {
    var ip_size = $(".width20:last  .photo").size();
    if (ip_size < 3) {
        $(".width20:last .photo").removeClass("last");
        for (var i = 0; i < 3 - ip_size; i++) $(".width20:first .photo").eq(i).clone().appendTo($(".width20:last"));
        $(".width20:last .photo:last").addClass("last");
        
    }
    $("#shadow").css({opacity: "0.7", top: "0", left: "0"});
    $("a.tipon").click(function(){
		$("#shadow").fadeIn(300);
		var topscroll = $(document).scrollTop();
		//alert(topscroll);
		$(this).parents("li").next("div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(0) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(0) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(1) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(1) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(2) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(2) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(3) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(3) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(4) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(4) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(5) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(5) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(6) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(6) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(7) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(7) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	$("#content ul:eq(8) li:eq(0) a").click(function(){
		var topscroll = $(document).scrollTop();
		$("#content ul:eq(8) div.tip").css({top: topscroll+100+"px"}).fadeIn(400);
		return false;
	});
	
	$("a.tip_off").click(function(){
		$("#shadow").fadeOut(400);
		$(this).parents("div.tip").fadeOut(300);
	});
});
$(window).load(function() {
    var getwidth = $("#move div.width20").width();
    var cPosition = $("#move div.width20").size();
    var fulwidth = cPosition * getwidth;
    var k = -1 * getwidth;
    var position = 1;
    var koef = k * position;
    var j = 1;
    var active = 0;
    if (cPosition > 1)
        $("#move").everyTime(5000, function(i) {
            //alert(position);

            $("#move").animate({ marginLeft: koef + "px" }, 1000);
            //max=total count - 2
            active = -1 * koef / getwidth;
            //        if (koef == 0) { active = 0 }
            //        if (koef == -980) { active = 1 }
            //        if (koef == -1960) { active = 2 }
            //        if (koef == -2940) { active = 3 }
            //        if (koef == -3920) { active = 4 }
            $("#control a").removeClass("active");
            $("#control a").eq(active).addClass("active");

            if (position > cPosition - 2) { j = -1; }
            if (position <= 0) { j = 1; }
            position = position + j;
            koef = k * position;
        });
    $("#control a").click(function() {
        $("#control a").removeClass("active");
        $(this).addClass("active");

        koef = -980;
        position = $.inArray(this, $('#control a'));
        $("#move").stop().animate({ marginLeft: koef * position + "px" }, 1000);

        return false;

    });
    //    $("#control a:eq(0)").click(function() {
    //        //        $("#move").stop().animate({ marginLeft: "0px" }, 1000);
    //        koef = -980;
    //        position = 0;
    //        $("#move").stop().animate({ marginLeft: koef * position + "px" }, 1000);
    //        return false;
    //    });
    //    $("#control a:eq(1)").click(function() {
    //        //        $("#move").stop().animate({ marginLeft: "-980px" }, 1000);
    //        koef = -980;
    //        position = 1;
    //        $("#move").stop().animate({ marginLeft: koef * position + "px" }, 1000);
    //        return false;
    //    });
    //    $("#control a:eq(2)").click(function() {
    //        //        $("#move").stop().animate({ marginLeft: "-1960px" }, 1000);
    //        koef = -980;
    //        position = 2;
    //        $("#move").stop().animate({ marginLeft: koef * position + "px" }, 1000);
    //        return false;
    //    });
    //    $("#control a:eq(3)").click(function() {
    //        //        $("#move").stop().animate({ marginLeft: "-2940px" }, 1000);
    //        koef = -980;
    //        position = 3;
    //        $("#move").stop().animate({ marginLeft: koef * position + "px" }, 1000);
    //        return false;
    //    });
    //    $("#control a:eq(4)").click(function() {
    //        //        $("#move").stop().animate({ marginLeft: "-3920px" }, 1000);
    //        koef = -980;
    //        position = 4;
    //        $("#move").stop().animate({ marginLeft: koef * position + "px" }, 1000);
    //        return false;
    //    });
});