var cancelInterval = 0;
var cancelNewsInterval = 0;
$(document).ready(function() {
    $("img.Htab").click(function(){
        if (!$(this).parent().children().is(':animated'))
        {
            var $tab = $(this);
            if ($tab.attr("id") == $("img.Htab:last").attr("id"))
            {
                $tab.css("position","relative");
                $tab.css("left","0px");
            }
            if (!$tab.hasClass("Htab-open"))
            {
                $("img.Htab-open").next().animate({
                    width:"0"
                },500);
                $tab.next().animate({
                    width:"200"
                },500,"linear",function(){
                    $("img.Htab-open").removeClass("Htab-open");
                    $tab.addClass("Htab-open");
                    if ($tab.attr("id") != $("img.Htab:last").attr("id"))
                    {
                        //$("img.Htab:last").css("position","absolute");
                        //$("img.Htab:last").css("right","52px");
                        $("img.Htab:last").css("position","relative");
                        $("img.Htab:last").css("right","0px");
                    }
                });
            }
            return false;
        }
    });

    /*************************************** news ***************************************/
    $("h2.tab").bind("mouseover",function(){
        $(this).addClass("tab-over");
    }).bind("mouseout",function(){
        $(this).removeClass("tab-over");
    });
    $("h2.tab").click(function(){
        cancelNewsInterval =1;
        if (!$(this).parent().children().is(':animated'))
        {
            var $tab = $(this);
            if ($tab.attr("id") == $("h2.tab:last").attr("id"))
                $tab.css("position","relative");

            if (!$tab.hasClass("tab-open"))
            {


                $("h2.tab-open").next().animate({
                    height:"0"
                },500);
                $tab.next().animate({
                    height:"180"
                },500,"linear",function(){
                    $("h2.tab-open").html($("h2.tab-open").html().replace("(-)&nbsp;","(+)"));
                    $tab.html($tab.html().replace("(+)","(-)&nbsp;"));
                    $("h2.tab-open").removeClass("tab-open");
                    $tab.addClass("tab-open");
                    if ($tab.attr("id") != $("h2.tab:last").attr("id"))
                        $("h2.tab:last").css("position","absolute");
                });
            }
            return false;
        }
    });


    /*********************************** Events *******************************************/
    $("a.eventsTab").mouseover(function(){
        //if (!$(this).hasClass("eventsTabOpen"))
        //{
        $(this).css("width","auto");
        $(this).css("background-position","99% center");
        $(this).children("div.EventTitleDiv").show();
    //}
    });
    $("a.eventsTab").mouseout(function(){
        //if (!$(this).hasClass("eventsTabOpen"))
        // {
        $(this).css("width","45px");
        $(this).css("background-position","10px 5px");
        $(this).children("div.EventTitleDiv").hide();
    //}
    });
    $(".stop").bind("mouseover",function(){
        //$(this).parent().animate({width:"200px"},0);

        });
    $("a.eventsTab").click(function(){
        cancelInterval =1;
        if (!$(this).parent().children().is(':animated'))
        {
            /*if ($(':animated').length) {
                    return false;
                    }*/

            var $tab = $(this);
            /* if ($tab.attr("id") == $("h2.tab:last").attr("id"))
	                    $tab.css("position","relative");*/

            if (!$tab.next().hasClass("eventsDivOpen"))
            {
                //$tab.animate({width:"100px"},500);
                // $("a.eventsTabOpen").animate({width:"75px"},500);
                $(".eventsDivOpen").fadeOut("slow",function(){
                    $tab.next().fadeIn("slow");
                    $(".eventsDivOpen").removeClass("eventsDivOpen");
                    $tab.next().addClass("eventsDivOpen");
                });

            /*if ($tab.attr("id") != $("h2.tab:last").attr("id"))
	                           $("h2.tab:last").css("position","absolute");  	                   */
            }

            return false;
        }
    });

    /************************************* Header Bottom Menu *****************************************/
    $(".headerBottomMenuItem").bind("mouseover",function(){
        $(".headerBottomMenuItem").each(function(){
            $(this).removeClass(this.id + "-over");
        });
        $(this).addClass(this.id + "-over");
        $(".bottomMenuContDiv").each(function(){
            $(this).hide();
        });
        $("#" + this.id + "-contents").show();
    });
    /**************************************************************************************************/
    $(".confDiv").click(function(){
        $(this).parent().children(".confCont").hide();
        $(this).next().next().next().show();
        $(this).parent().children(".confDiv").css("color","white");
        $(this).css("color","red");
    });
});
$(document).ready(function() {
    function Set_Cookie( name, value, expires )
    {
        // set time, it's in milliseconds
        var today = new Date();
        today.setTime( today.getTime() );

        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
         */
        if ( expires )
        {
            expires = expires * 1000 * 60 * 60 ;
        }
        var expires_date = new Date( today.getTime() + (expires) );

        document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" );
    }
    // this function gets the cookie, if it exists
    // don't use this, it's weak and does not handle some cases
    // correctly, this is just to maintain legacy information
    function Get_Cookie( name ) {

        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) &&
            ( name != document.cookie.substring( 0, name.length ) ) )
            {
            return null;
        }
        if ( start == -1 ) return null;
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
    }


    var rv = -1;
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );

    if (navigator.appName=="Microsoft Internet Explorer" && rv < 7) {
        var msgV = "\u0639\u0630\u0631\u0627\u064b, \u064a\u0628\u062f\u0648 \u0627\u0646\u0643 \u062a\u0633\u062a\u062e\u062f\u0645 \u0645\u062a\u0635\u0641\u062d \u0627\u0646\u062a\u0631\u0646\u062a \u0627\u0643\u0633\u0628\u0644\u0648\u0631\u0631 \u0666 \u0627\u0648 \u0627\u0642\u0644 , \u0648\u0647\u0630\u0627 \u0642\u062f \u064a\u0633\u0628\u0628 \u0628\u0639\u0636 \u0627\u0644\u0645\u0634\u0627\u0643\u0644 \u0641\u064a \u0639\u0631\u0636 \u0627\u0644\u0635\u0641\u062d\u0627\u062a, \u064a\u0641\u0636\u0644 \u062a\u062d\u062f\u064a\u062b \u0627\u0635\u062f\u0627\u0631 \u0645\u062a\u0635\u0641\u062d\u0643 \u0627\u0644\u0649 \u0627\u0644\u0646\u0633\u062e\u0629 7 \u0641\u0645\u0627 \u0641\u0648\u0642\u060c \u0627\u0648 \u0627\u0633\u062a\u062e\u062f\u0627\u0645 \u0645\u062a\u0635\u0641\u062d \u0641\u0627\u064a\u0631\u0641\u0648\u0643\u0633 3.5 \u0641\u0645\u0627 \u0641\u0648\u0642";
        if (Get_Cookie("ARBUFIRSTVISIT") == null || Get_Cookie("ARBUFIRSTVISIT").toString() == "false" )
        {
            alert(msgV.toString());
            Set_Cookie ("ARBUFIRSTVISIT",true,1);
        }
        $("#BrowserWarningTR").css("display", "table-row");
        $("#BrowserWarningDiv").text(msgV);
    }
    $(".moreFLinks").click(function(){
        if (!$(this).parent().children().is(':animated'))
        {
            $("#" + this.id + "-content").show(500, function() {}
                );
            $("#" + this.id).hide(500, function() {}
                );
        }
        return false;
    });
    $(".lessFLinks").click(function(){
        if (!$(this).parent().children().is(':animated'))
        {
            $("#" + this.id + "-content").hide(500, function() {}
                );
            $("#" + this.id).show(500, function() {}
                );
        }
        return false;
    });
});
$(document).unload(function() {
    function Get_Cookie( name ) {

        var start = document.cookie.indexOf( name + "=" );
        var len = start + name.length + 1;
        if ( ( !start ) &&
            ( name != document.cookie.substring( 0, name.length ) ) )
            {
            return null;
        }
        if ( start == -1 )
            return null;
        var end = document.cookie.indexOf( ";", len );
        if ( end == -1 ) end = document.cookie.length;
        return unescape( document.cookie.substring( len, end ) );
    }
    // this deletes the cookie when called
    function Delete_Cookie( name  ) {
    {
        var cookie_date = new Date ( );  // current date & time
        cookie_date.setTime ( cookie_date.getTime() - 1 );
        document.cookie = name += "=false; expires=" + cookie_date.toGMTString();
    }

    }

    Delete_Cookie("ARBUFIRSTVISIT");
});

