/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
jQuery.noConflict();
    
jQuery(document).ready(Init);

function Init()
{
    //настройка меню. Находим все области класса adiv, определяем высоту элемента а
    //в ней и для области класса adiv задаем высоту на 2 пикселя больше
    /*array_adiv = jQuery('.adiv').get();
        k=array_adiv.length;
        for (i=0;i<k; i++)
            {
                element=array_adiv[i];
                height=jQuery('a',element).height();
                jQuery(element).css('height',height+2);
            }*/

    jQuery('a','#mainmenu').mouseover(showLine);
    jQuery('a','#mainmenu').mouseout(hideLine);
    //jQuery('a','.table_menu').click(showImage);
    jQuery('a').click(openSub);
    //jQuery('.sub1')
    //строка вставляет информер курсов валют
    jQuery('#met').html('<a href="http://www.informer.ru/cgi-bin/redirect.cgi?id=172_1_1_48_39_1-0&url=http://www.rbc.ru&src_url=usd/usd_dm_cb_000000_88x61.gif" target="_blank"><img src="http://pics.rbc.ru/img/grinf/usd/usd_dm_cb_000000_88x61.gif?'+ Math.floor( 100000*Math.random() ) + '" WIDTH=88 HEIGHT="61" border=0></a>');
    jQuery(window).scroll(doScroll);
    jQuery('#consult').css('top',jQuery(document).scrollTop()+jQuery(window).height()-225);
        
    jQuery('#closeConsult').click(closeConsult);
    jQuery('.pravoCon').click(closeConsult);
}


function showLine()
{
    parentQ=jQuery(this).parent();
    jQuery('.line:first',parentQ).addClass('fonwidline');
}

function hideLine()
{
    //jQuery(this).removeClass('over_link')

    parentQ = jQuery(this).parent();
    if (!jQuery('div:first',parentQ).hasClass('current_punkt'))
    {
        jQuery('.line:first',parentQ).removeClass('fonwidline');
    }
}


function openSub()
{
    parentA = jQuery(this).parent().parent();
    //alert('hello');

    if (jQuery('#child',parentA).hasClass('hide'))
    {
        jQuery('#child',parentA).removeClass('hide');
        jQuery('#child',parentA).show();
    }
    else
    {
        jQuery('#child',parentA).hide();
        jQuery('#child',parentA).addClass('hide');
    }


}

//код для работы с галереей. Начало
jQuery(document).ready(function(){
    //alert('Hello');
    jQuery("a[rel=group]").fancybox({
        'titleShow':false,
        'cyclic':true,
        'centerOnScroll':true
    });

    jQuery("a#couseReserve").click(function()
    {
        //alert('hello');
        var url = jQuery(this).attr('href');
        //alert(url);
        jQuery.post(url, {
            controller:'ajax'
        }, function(data){
            jQuery.fancybox(data,{
                'width':800,
                'height':600,
                'centerOnScroll':true
            });
        });
        return false;
    });
});

jQuery(document).ready(function()
{
    listGal = jQuery('#galeryList td.element');
    sizeGal = listGal.length;
    //alert(size);
    startGal = 0;
    mainStart=0;
    endGal = 3;
    for(i = 3; i < sizeGal; i++)
    {
        jQuery(listGal[i]).css('display', 'none');
    }
    jQuery('#prev').click(prev);
    jQuery('#next').click(next);
});

function prev()
{
    if((endGal - 3) > 0)
    {
        endGal--;
        jQuery(listGal[endGal]).css('display', 'none');
        startGal--;
        jQuery(listGal[startGal]).removeAttr('style');
    }
    else
    {//alert('hello');
        tdHtml=jQuery(listGal[sizeGal-1]).html();
        jQuery(listGal[sizeGal-1]).remove();
        jQuery('#prev').after('<td class="element razmer">'+tdHtml+'</td>');
        listGal = jQuery('#galeryList td.element');
        jQuery(listGal[3]).css('display', 'none');
        jQuery("a[rel=group]").fancybox({
            'titleShow':false, 
            'cyclic':true,
            'centerOnScroll':true
        });

    }
}
function next()
{
    if((startGal + 3) < sizeGal)
    {
        jQuery(listGal[startGal]).css('display', 'none');
        startGal++;
        jQuery(listGal[endGal]).removeAttr('style');
        endGal++;
    }
    else
    {
        //listGal[]=listGal[mainStart]
        //берем html код первого элемента
        tdHtml=jQuery(listGal[0]).html();
        //alert(tdHtml);
        jQuery(listGal[0]).remove();
        jQuery(listGal[sizeGal-1]).after('<td class="element razmer">'+tdHtml+'</td>');
        //меняем местами первый и последний элемент массива
        listGal = jQuery('#galeryList td.element');
        jQuery(listGal[sizeGal-4]).css('display', 'none');
        //sizeGal = listGal.length;
        jQuery("a[rel=group]").fancybox({
            'titleShow':false, 
            'cyclic':true,
            'centerOnScroll':true
        });
    }

}
//код для работы с галереей. Конец


function mydoNight()
{
    var nightScreen = document.getElementById('overlay');
    if (!nightScreen)
    {
        jQuery('body').append('<div id="overlay1" class="overlayBG1">fhgfhgfhgfh</div>')
        jQuery('#overlay1').css('visibility', 'visible');
    } else
{
        nightScreen.style.display = 'block';
    }
}
function mydoDay()
{
    var nightScreen = document.getElementById('overlay1');
    if (nightScreen) nightScreen.style.display = 'none';
}

jQuery(document).ready(function()
{
    list = jQuery('#emitentList td.elementEmitent');
    size = list.length;
    //alert(size);
    start = 0;
    end = start+5;
    for(i = start+5; i < size; i++)
    {
        jQuery(list[i]).css('display', 'none');
    }
    for(j = 0; j < start; j++)
    {
        jQuery(list[j]).css('display', 'none');
    }

    list1 = jQuery('#emitentList1 td.elementEmitent1');
    for(i = start+5; i < size; i++)
    {
        jQuery(list1[i]).css('display', 'none');
    }
    for(j = 0; j < start; j++)
    {
        jQuery(list1[j]).css('display', 'none');
    }

    jQuery('#prevEl').click(prevEl);
    jQuery('#nextEl').click(nextEl);
    jQuery('#prevEl1').click(prevEl);
    jQuery('#nextEl1').click(nextEl);
});

//код для работы с эмитентом
function prevEl()
{
    if((end - 5) > 0)
    {
        end--;
        jQuery(list[end]).css('display', 'none');
        jQuery(list1[end]).css('display', 'none');
        start--;
        jQuery(list[start]).removeAttr('style');
        jQuery(list1[start]).removeAttr('style');
    }
}
function nextEl()
{
    if((start + 5) < size)
    {
        jQuery(list[start]).css('display', 'none');
        jQuery(list1[start]).css('display', 'none');
        start++;
        jQuery(list[end]).removeAttr('style');
        jQuery(list1[end]).removeAttr('style');
        end++;
    }

}

function showMessage(mes)
{
    jQuery.fancybox("<font style='font-weight:bold; color:#4D4D4D;'>"+mes+"</font>",{
        "width":800,
        "height":600,
        'centerOnScroll':true
    });
}

function doScroll() {
    //alert(jQuery(document).scrollTop()+jQuery(window).height()-225);
    //alert(jQuery(window).height()+' '+jQuery(document).height()+' '+jQuery(document).scrollTop());
    if (jQuery(document).scrollTop()+jQuery(window).height()<jQuery(document).height())
        jQuery('#consult').css('top',jQuery(document).scrollTop()+jQuery(window).height()-225);
}
function closeConsult() {
    //parent = jQuery(this).parent().parent().parent().parent();
    //alert('888');
    //jQuery('.levoCon').hide();
    //
    //jQuery('#consult').hide();
    //alert(jQuery('.levoCon').css('display','none'));
    jQuery('.levoCon').css
    if (jQuery('.levoCon').css('display')=='none')
    {
        jQuery('#consult').css('width','441px');
        jQuery('.levoCon').css('display','block');
    }
    else
    {
        jQuery('.levoCon').css('display','none');
        jQuery('#consult').css('width','21px');
    }
}


//скрипт снежинки
snow_intensive=400;
snow_speed=30000;
snow_src=new Array('/images/design/snows/sneg1.gif','/images/design/snows/sneg2.gif','/images/design/snows/sneg3.gif');

jQuery(document).ready(snow_start);

function snow_start() {
    snow_id=1;
    snow_y=jQuery("#snowblock").height()-30;
    setInterval(function() {
        snow_x=Math.random()*document.body.offsetWidth-100;
        snow_img=(snow_src instanceof Array ? snow_src[Math.floor(Math.random()*snow_src.length)] : snow_src);
        snow_elem='<img class="png" id="snow'+snow_id+'" style="position:absolute; left:'+snow_x+'px; top:0;z-index:10000" src="'+snow_img+'"/>';
        jQuery("#snowblock").append(snow_elem);
        snow_move(snow_id);
        snow_id++;
    },snow_intensive);
}

function snow_move(id) {
    jQuery('#snow'+id).animate({
        top:snow_y,
        left:"+="+Math.random()*100
        },snow_speed,function() {
        jQuery(this).empty().remove();
    });
}
