// JavaScript Document

//браузер
var ua = navigator.userAgent.toLowerCase();
var isIE = (ua.indexOf("msie") != -1);
var isOpera = (ua.indexOf("opera") != -1);
// Gecko = Mozilla + Firefox + Netscape
var isGecko = (ua.indexOf("gecko") != -1);
//Chrome
var isChrome = (ua.indexOf("chrome") != -1);
// Safari, используется в MAC OS
var isSafari = (ua.indexOf("safari") != -1);
// Konqueror, используется в UNIX-системах
var isKonqueror = (ua.indexOf("konqueror") != -1);

$(document).ready(
	function () {

	    $(".ico a").hover(function () {
	        $(this).children("img").css('margin-top', '-10px');
	    }, function () {
	        $(this).children("img").css('margin-top', '0');
	    });

	    $(".navigation a").hover(function () {
	        $(this).addClass("hover");
	    }, function () {
	        $(this).removeClass("hover");
	    });




	    $(".nav_head").hover(function () {
	        $(this).children(".nav_body").show();
	    }, function () {
	        $(this).children(".nav_body").hide();
	    });


	    $(".darker").height($(document).height());


	    $(".arrows").click(function () {
	        $(".center_big").hide("slow");
	        $(".center").show("slow");
	    });

	    $(".basket .close").click(function () {
	        $(this).parents(".item").animate({ opacity: 'hide' }, "slow");
	    });

	    $(".table tr:nth-child(even)").addClass("chet");

	    $(".expanded_link").toggle(function () {
	        $(this).text("Свернуть");
	        $(this).addClass("close");
	        $(".expanded_search").slideDown();
	    }, function () {
	        $(this).text("Расширенный поиск");
	        $(this).removeClass("close");
	        $(".expanded_search").slideUp();
	    });

	    //windows ***********************************
	    $(".open_login").click(function () {
	        $("#divLock").addClass("visible");
	        $("#w_login").addClass("visible");
	        var w = document.getElementById("w_login");
	        w.style.top = TopMustBe(w) + "px";
	        w.style.left = LeftMustBe(w) + "px";
	        window.onresize = function () { WindowChangeEvent(w); }
	        window.onscroll = function () { WindowChangeEvent(w); }
	    });
	    $("#close_login").click(function () {
	        $("#divLock").removeClass("visible");
	        $("#w_login").removeClass("visible");
	        window.onresize = null;
	        window.onscroll = null;
	    });
	    $(".open_registration").click(function () {
	        $("#w_login").removeClass("visible");
	        $("#w_registration").addClass("visible");
	        var w = document.getElementById("w_registration");
	        w.style.top = TopMustBe(w) + "px";
	        w.style.left = LeftMustBe(w) + "px";
	        window.onresize = function () { WindowChangeEvent(w); }
	        window.onscroll = function () { WindowChangeEvent(w); }
	    });
	    $("#close_registration").click(function () {
	        $("#divLock").removeClass("visible");
	        $("#w_registration").removeClass("visible");
	        window.onresize = null;
	        window.onscroll = null;
	    });
	    //result voting ***********************************
	    var w_resultVoting = document.getElementById("w_resultVoting");
	    if (w_resultVoting) {
	        $(".open_resultVoting").click(function () {
	            $("#divLock").addClass("visible");
	            $("#w_resultVoting").addClass("visible");
	            w_resultVoting.style.top = TopMustBe(w_resultVoting) + "px";
	            w_resultVoting.style.left = LeftMustBe(w_resultVoting) + "px";
	            window.onresize = function () { WindowChangeEvent(w_resultVoting); }
	            window.onscroll = function () { WindowChangeEvent(w_resultVoting); }
	        });
	        $("#close_resultVoting").click(function () {
	            $("#divLock").removeClass("visible");
	            $("#w_resultVoting").removeClass("visible");
	            window.onresize = null;
	            window.onscroll = null;
	        });
	    }
	    //*******************************************
	    //faq message ***********************************
	    var w_message = document.getElementById("w_message");
	    if (w_message) {
	        $(".open_message").click(function () {
	            $("#divLock").addClass("visible");
	            $("#w_message").addClass("visible");
	            w_message.style.top = TopMustBe(w_message) + "px";
	            w_message.style.left = LeftMustBe(w_message) + "px";
	            window.onresize = function () { WindowChangeEvent(w_message); }
	            window.onscroll = function () { WindowChangeEvent(w_message); }
	        });
	        $("#close_message").click(function () {
	            $("#divLock").removeClass("visible");
	            $("#w_message").removeClass("visible");
	            window.onresize = null;
	            window.onscroll = null;
	        });
	    }
	    //subscribe ***********************************
	    var w_subscribe = document.getElementById("w_subscribe");
	    if (w_subscribe) {
	        $(".open_subscribe").click(function () {
	            $("#divLock").addClass("visible");
	            $("#w_subscribe").addClass("visible");
	            w_subscribe.style.top = TopMustBe(w_subscribe) + "px";
	            w_subscribe.style.left = LeftMustBe(w_subscribe) + "px";
	            window.onresize = function () { WindowChangeEvent(w_subscribe); }
	            window.onscroll = function () { WindowChangeEvent(w_subscribe); }
	        });
	        $("#close_subscribe").click(function () {
	            $("#divLock").removeClass("visible");
	            $("#w_subscribe").removeClass("visible");
	            window.onresize = null;
	            window.onscroll = null;
	        });
	    }
	    //*******************************************


	    if (document.getElementById("albumitems")) {
	        $(".gallery1 a[rel^='prettyPhoto'],.menulist a[rel^='prettyPhoto']").prettyPhoto({ theme: 'facebook' });
	    }

	    //audio player
	    var sp_serverUrl = document.getElementById("sp_serverUrl");
	    if (sp_serverUrl) {
	        // default options
	        //$(".mp3").jmp3();
	        // custom options
	        $(".aaudio").jmp3({
	            backcolor: "B40000",
	            forecolor: "ffffff",
	            width: 175,
	            showdownload: "true",
	            showfilename: "false"
	        });
	    }
	});

	function AjaxSaveNotification(text) {
	    $.jGrowl('<div><div class="img"></div>' + text + '</div>', { life: 3000 });
	}

function WindowChangeEvent(w) {
	if (w) {
	    w.style.top = TopMustBe(w) + "px";
	    w.style.left = LeftMustBe(w) + "px";
	}
}
function TopMustBe(w) {
    var t = 0;
    var scrollTop = (document.body.scrollTop || document.documentElement.scrollTop);
    if (isOpera)
        t = window.innerHeight / 2 + scrollTop - w.offsetHeight / 2;
    else
        if (isIE)
            t = document.documentElement.offsetHeight / 2 + scrollTop - w.offsetHeight / 2;
        else
            t = window.innerHeight / 2 + scrollTop - w.offsetHeight / 2;
    return t;
}
function LeftMustBe(w) {
    var l = 0;
    var scrollLeft = (document.body.scrollLeft || document.documentElement.scrollLeft);
    if (isIE) {
        l = document.documentElement.offsetWidth / 2 + scrollLeft - w.offsetWidth / 2;
    }
    else
        l = document.documentElement.clientWidth / 2 + scrollLeft - w.offsetWidth / 2;
    return l;
}

var captcha = null;
var reg_preloader = null;
var captchaIntervalID = null;
var capImage = null;

function UpdateCaptcha() {
    captcha = document.getElementById("captcha");
    preloader = document.getElementById("reg_preloader");
    if (captcha) {
        captcha.style.display = "none";
        preloader.style.display = "block";
        var n = Math.random() * 100000;
        n = Math.round(n);
        captcha.src = null;
        capImage = new Image();
        capImage.src = "captcha" + n + ".aspx";
        captchaIntervalID = setInterval(CaptchaOnLoad, 100);
    }
}

function CaptchaOnLoad() {
    if (capImage.complete) {
        preloader.style.display = "none";
        captcha.src = capImage.src;
        captcha.style.display = "block";
        clearInterval(captchaIntervalID);
    }
}
