﻿/// <reference path="../scripts/jquery-vsdoc.js" />
var Pics = new Array();
var $bevbot = null;
var $footer = null;
var setFooter = function() {
    
    var leftContH = $("div.contentleft").height();
    var contentBoxH = $("div.contentbox").height();
    if (leftContH > contentBoxH) {
        $("div.contentbox").height(leftContH - 4);
        $bevbot.css("top", $(document).height() - 52);
    }
    else if (contentBoxH > leftContH) {
        $("div.contentleft").height(contentBoxH);
        $bevbot.css("top", $(document).height() - 52);

    }
    $bevbot.show();
    $footer.show();
}

$(function() {

$spanH1=$("#spanH1");
if ($spanH1.length>0){
  $h1=$(".TextHeader:has(h1)").before("<div class='TextHeader'><div class='header1'>О компании</div></div>")
  $h1.insertBefore($spanH1);
}

$TextHeader=$('.TextHeader');
if ($TextHeader.height()>30){
$TextHeader.css('width','auto');
}
$bevbot = $("div.bgbevelBot").hide()
$footer=$("div#footer").hide()
    if ($(".ModelGallery > .Gallery > span").length > 0) {
        $(".ModelGallery").show();
        ShowGallery();
    }
    if ($(".ModelGallery > .Documents > a").length > 0) {
        $(".ModelGallery").show();
    }
    $("table.Format").each(formatTable);
    
    $(".TopMenuPadItem:has(.sel)").addClass("TopMenuPadItemSelected");
    $(".LeftMenuLevel1:has(.sel)").addClass("LeftMenuSelected").css("background-color", "transparent").css("color", "Black").css("background-image", "url(files/design/leftmenubevelsel.gif)");
    $(".LeftMenuLevel3:has(.sel)").addClass("LeftMenuSelected").css("background-image", "none");
    $("a[href*=popup.aspx]").live("click", function(Event) {
        Event.preventDefault();
        popUpW($(this).attr("href"));
        return false;
    })
    setTimeout('setFooter()', 50);

});


var popUpW = function(Uri, w, h) {
    w = (w) ? w : 800;
    h = (h) ? h : 600;
    var l = $(window).width() / 2 - w / 2;
    var t = $(window).height() / 2 - h / 2 + 50;
    var opt = "left=" + l + ",top=" + t + ",height=" + h + ",width=" + w + ",status=yes,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no";
    window.open(Uri, "", opt);
    return false;
}

var ShowGallery = function() {
    $(".ModelGallery > .Gallery > span").each(function() {
        var aPic = $(this);
        var Path = aPic.text().replace(/[^\\\/]*$/, '');
        var fname = aPic.text().substr(Path.length);
        var stem = fname.replace(/\..*/, '');
        var ext = fname.substr(stem.length);
        Pics.push({ 'path': Path, 'stem': stem, 'ext': ext, 'title': aPic.attr('title') });
    });
    if (Pics.length == 0) return;
    var $ModelCallery = $(".ModelGallery").prepend($("<a id='TopPic' title='" + Pics[0].title + "' style='margin-left:20px' href='" + Pics[0].path + Pics[0].stem + Pics[0].ext + "' target='_new'><img src='files/thumbs/" + Pics[0].stem + "_x220" + Pics[0].ext + "' alt='" + Pics[0].title + "' title='" + Pics[0].title + "' border='0'/></a>"));
    $ModelCallery.prependTo($ModelCallery.parent());
    if (Pics.length < 2) return;
    $("<div id='GalleryPanel' style='margin-left:20px;margin-top:5px;overflow:hidden;width:220px;height:74px;text-align:middle'></div>").insertBefore('.Gallery');
    for (var i = 0; i < Pics.length; i++) {
        if (i > 2) break;
        $("<img src='files/thumbs/" + Pics[i].stem + "_x70" + Pics[i].ext + "' alt='" + Pics[i].title + "' title='" + Pics[i].title + "' position='" + i + "' style='border:solid 1px Black;margin-right:1px;cursor:pointer' border='0'/>").appendTo("#GalleryPanel")
        .click(imageClick);
    }
    if (Pics.length > 3) {
        $("<img border='0' src='files/design/left.gif' style='position:absolute;top:260px;left:0px;cursor:pointer' />")
        .appendTo(".ModelGallery")
        .hover(function() { $(this).attr("src", "files/design/left_sel.gif"); },
           function() { $(this).attr("src", "files/design/left.gif"); })
        .click(moveRight);
        $("<img border='0' src='files/design/right.gif' style='position:absolute;top:260px;left:243px;cursor:pointer' />")
        .appendTo(".ModelGallery")
        .hover(function() { $(this).attr("src", "files/design/right_sel.gif"); },
           function() { $(this).attr("src", "files/design/right.gif"); })
        .click(moveLeft);
    } else {
    $ModelCallery.css("margin-right", "0px").children("*").css("margin-left", "0px");
    }
    
}
var moveLeft = function() {
    var Pos = parseFloat($("#GalleryPanel img:last").get(0).getAttribute("position"));
    if (Pos >= Pics.length - 1) {
        Pos = 0
    } else {
        Pos++;
    }
    $("#GalleryPanel img:first").remove();
    $("<img src='files/thumbs/" + Pics[Pos].stem + "_x70" + Pics[Pos].ext + "' alt='" + Pics[Pos].title + "' title='" + Pics[Pos].title + "' position='" + Pos + "' style='border:solid 1px Black;margin-right:1px;cursor:pointer' border='0'/>").appendTo("#GalleryPanel")
        .click(imageClick);
    $("#GalleryPanel img:first").each(imageClick);
}
var moveRight = function() {
var Pos = parseFloat($("#GalleryPanel img:first").get(0).getAttribute("position"));
    if (Pos <= 0) {
        Pos = Pics.length-1
    } else {
        Pos--;
    }
    $("<img src='files/thumbs/" + Pics[Pos].stem + "_x70" + Pics[Pos].ext + "' alt='" + Pics[Pos].title + "' title='" + Pics[Pos].title + "' position='" + Pos + "' style='border:solid 1px Black;margin-right:1px;cursor:pointer' border='0'/>").prependTo("#GalleryPanel")
        .click(imageClick);
    $("#GalleryPanel img:last").remove();
    $("#GalleryPanel img:first").each(imageClick);
}
var imageClick = function() {
var i = parseFloat($(this).get(0).getAttribute("position"));
    $("#TopPic").attr("title", Pics[i].title).attr("href", Pics[i].path + Pics[i].stem + Pics[i].ext);
    $("#TopPic img").attr("title", Pics[i].title).attr("alt", Pics[i].title).attr("src", "files/thumbs/" + Pics[i].stem + "_x220" + Pics[i].ext);
}
var formatTable = function() {
var table = $(this).css("border", "none 0px transparent");
    $("td", table).css("border", "solid 1px #f5f5f5");
    table.wrap("<div class='tbWrap'></div>").parent().before("<div style='clear:both;font-size:1px;'>&nbsp;</div>").width(table.outerWidth()).prepend($("<div class='ttl'></div><div class='ttr'></div><div class='tbl'></div><div class='tbr'></div>"));
    $("tr:odd > td", table).css("background-color", "#f5f5f5");
    $("tr:even", table).find("td:first").css("background-color", "#f6b900");
    $("tr:odd", table).find("td:first").css("background-color", "#f5f5c5");
    
}
var al = function(st) {
    setTimeout("alert('"+st+"')", 500);
}