/*
function show_popup(id) {
//	$("#" + id).fadeIn(500);
	$("#" + id).show();
}

function show_popup_2(id) {
	$("#" + id).css("display", "table");
}

function hide_popup(id) {
//	$("#" + id).fadeOut(500);
	$("#" + id).hide();
}

function show_license(img) {
    var strimg = "/images/lic_" + img + ".jpg";
    $("#licence .over img").attr("src", strimg);
    show_popup("licence");
}

function hide_licence() {
    $("#licence .over img").attr("src", "");
    hide_popup("licence");
}

function hide_team_item() {
    $("#team_item .over").html("");
    hide_popup("team_item");
}
*/

function show_license(img) {
    var strimg = "/images/lic_" + img + ".jpg";
    $("#cardpopblock .licence").html('<img src="' + strimg + '" />');
    setTimeout("open_popup()", 200);
//    open_popup();
}

function show_team_item(id) {
    $("#curr_team_id").val(id);
    var prev_id = $("#prev_" + id).val();
    var next_id = $("#next_" + id).val();
    $(".arrow-left_Shadow").hide();
    $(".arrow-right_Shadow").hide();
    if (prev_id != "") $(".arrow-left_Shadow").show();
    if (next_id != "") $(".arrow-right_Shadow").show();
    $.get("detail.php", {TID: id}, function(data){
//        $("#team_item .over").html(data);
        $("#cardpopblock .team-one").replaceWith(data);
        open_popup();
        set_arrows_position();
//        show_popup("team_item");
    });
}

function load_team_item(id) {
    $("#cardpopblock .team-one").hide();
    $("#team_waiting").show();
    heightshadow("cardpopblock");
    $("#curr_team_id").val(id);
    $(".arrow-left_Shadow").hide();
    $(".arrow-right_Shadow").hide();
    $.ajax({
        type: "POST",
        url: "detail.php",
        data: "TID=" + id,
//        async: false,
        success: function(data){
            $("#cardpopblock .team-one").replaceWith(data);
            $("#team_waiting").hide();
            $("#cardpopblock .team-one").show();
            heightshadow("cardpopblock");
            set_arrows_position();
            var prev_id = $("#prev_" + id).val();
            var next_id = $("#next_" + id).val();
            if (prev_id != "") $(".arrow-left_Shadow").show();
            if (next_id != "") $(".arrow-right_Shadow").show();
        }
    });
}

function set_arrows_position() {
    var arrow_height = 55;
    var block_height = document.getElementById("cardpopblock").clientHeight;
    var top_position = Math.round((block_height - arrow_height)/2);
    $(".arrow-left_Shadow").css("top", top_position + "px");
    $(".arrow-right_Shadow").css("top", top_position + "px");
}

$(document).ready(function(){
    $("#btn_close img").click(function(){
//        $("#team_item .over").html("");
        $("#cardpopblock .team-one").replaceWith('<div class="team-one"></div>');
        $(".arrow-left_Shadow").hide();
        $(".arrow-right_Shadow").hide();
        $("#shadow").attr("class", "");
        $("html").attr("class", "overauto");
    });

    $("#btn_close_2 img").click(function(){
        $("#shadow_2").attr("class", "");
        $("html").attr("class", "overauto");
    });

    $("#btn_close_3 img").click(function(){
        $("#shadow_3").attr("class", "");
        $("html").attr("class", "overauto");
    });

    $("#btn_close_portfolio img").click(function(){
        $("#shadow_portfolio").attr("class", "");
        $("html").attr("class", "overauto");
        $("#is_card_details").val("");
    });

    $("#btn_close_portfolio_small img").click(function(){
        $("#shadow_portfolio_small").attr("class", "");
        $("html").attr("class", "overauto");
        $("#is_card_details").val("");
    });

    $("#btn_close_tusk img").click(function(){
        $("#shadow_tusk").attr("class", "");
        $("html").attr("class", "overauto");
    });

    $("#btn_close_pwd img").click(function(){
        $("#shadow_pwd").attr("class", "");
        $("html").attr("class", "overauto");
    });

    $(".arrow-left_Shadow").click(function(){
        var curr_team_id = $("#curr_team_id").val();
        var prev_team_id = $("#prev_" + curr_team_id).val();
        if (prev_team_id != "") load_team_item(prev_team_id);
    });
    $(".arrow-right_Shadow").click(function(){
        var curr_team_id = $("#curr_team_id").val();
        var next_team_id = $("#next_" + curr_team_id).val();
        if (next_team_id != "") load_team_item(next_team_id);
    });

    var sUrl = document.location.href;
    var sInd = sUrl.indexOf("#");
    var sStr = "";
    if (sInd != -1) {
        sStr = sUrl.substr(sInd + 1);
    }
    if (sStr == "prospects") {
        open_popup();
    }
    else if (sStr == "tusk") {
        open_popup_par('_tusk');
    }
});

function open_popup() {
//    $(".shadowBlock").css("top", eval(document.documentElement.scrollTop) + 400 + "px");
    $("#shadow").attr("class", "on card");
    $("html").attr("class", "overhidden");
    $("#cardpopblock").focus();
    heightshadow("cardpopblock");
}

function open_popup_2() {
    $("#shadow_2").attr("class", "on card");
    $("html").attr("class", "overhidden");
    $("#cardpopblock_2").focus();
    heightshadow("cardpopblock_2");
}

function open_popup_3() {
    $("#shadow_3").attr("class", "on card");
    $("html").attr("class", "overhidden");
    $("#cardpopblock_3").focus();
    heightshadow("cardpopblock_3");
}

function open_popup_par(id_part) {
    $("#shadow" + id_part).attr("class", "on card");
    $("html").attr("class", "overhidden");
    $("#cardpopblock" + id_part).focus();
    heightshadow("cardpopblock" + id_part);
}

function heightshadow(object)
{
    var Block = document.getElementById(object);
    if (Block.className == 'bigImg'){
        var heightBlock = Block.clientHeight-45;
    } else {
        var heightBlock = Block.clientHeight;
    }
    for (i=0; i<Block.childNodes.length; i++) {
        if (Block.childNodes[i].className == 'l_Shadow') {
            Block.childNodes[i].style.height = heightBlock + 1 + 'px';
        }
        if (Block.childNodes[i].className == 'r_Shadow') {
            Block.childNodes[i].style.height = heightBlock + 1 + 'px';
        }
    }
}

function open_popup_loc(flag, id_part) {
    document.location.href = "#" + flag;
    if (id_part == "") {
        open_popup();
    } else {
        open_popup_par(id_part);
    }
}

