
var lang = (window.location.href.indexOf('.com/fa') > 0) ? 'fa' : 'en';



$(document).ready(function () {

    var page = (window.location.href + '');
    var menu = 0;
    if (page.indexOf(lang + '/' + 'photos') > -1) {
        menu = 1;
    } else if (page.indexOf(lang + '/' + 'blog') > -1) {
        menu = 2;
    } else if (page.indexOf(lang + '/' + 'faq') > -1) {
        menu = 3;
    } else if (page.indexOf(lang + '/' +'articles') > -1) {
        menu = 4;
    } else if (page.indexOf(lang + '/' + 'medicalinformation') > -1) {
        menu = 5;
    } else if (page.indexOf(lang + '/' + 'videos') > -1) {
        menu = 6;
    } else if (page.indexOf(lang + '/' + 'links') > -1) {
        menu = 7;
    } else if (page.indexOf(lang + '/' + 'about') > -1) {
        menu = 8;
    } else if (page.indexOf(lang + '/' + 'contact') > -1) {
        menu = 9
    } else if (page.indexOf(lang + '/' + 'special') > -1) {
        menu = 10;
    }

    if(menu > 0)
     $('#m' + menu).css({ backgroundPosition: '0 0' });


    //
    var objSearch = 3;

    var of = $('#c146').offset();

    if (lang == 'fa')
        $('#c147').css({ top: of.top + 24, left: of.left });
    else
        $('#c147').css({ top: of.top + 24, left: of.left - 143 });

    $('#c147').fadeOut('fast');
    $('#c146').click(openBalon);
    $('.c13').click(openBalon);

    function openBalon() {
        $('.c148').css({ display: "block" });
        //
        if ($('#c147').css('display') == 'none') {
            $('#c147').fadeIn('fast');
        } else {
            $('#c147').fadeOut('fast');
        }
    };

    function gotoSearchPage() {
        window.location.href = '/' + lang + '/search/?q=' + $('.c13').val() + '&s=' + objSearch;
    }

    //
    $('.c14').click(gotoSearchPage);
    $('.c13').keyup(function (e) {
        if (e != null) {
            if (e.keyCode == 13) {
                gotoSearchPage();
            }
        }
    });

    //
    $('.c148').click(function (e) {
        for (var i = 1; i < 5; i++)
            $('#search_' + i).css({ backgroundPosition: "0 0" });
        //
        objSearch = ($(this).attr('id') + '').replace('search_', '');
        $(this).css({ backgroundPosition: "0 -35px" });

    });


    $("#stat").hover(
		function () { $('#c62').css({ display: "block" }); },
		function () { $('#c62').css({ display: "none" }); }
	);
    $("#stat").mousemove(function (e) {
        var mousex = e.pageX + 10;
        var mousey = e.pageY - 100;
        $('#c62').css({ top: mousey, left: mousex });
    });

    /////////////
    var langShow = false;
    /*
    $('#c9').click(function () {

        if (!langShow) {
            $('#c11 img').fadeIn("slow");
        } else {
            $('#c11 img').fadeOut("fast");
        }
        // $('#c9').src = '/content/images/shared/r9.gif';
        $('#c9').attr('src', !langShow ? '/content/images/shared/r9.gif' : '/content/images/shared/r8.gif');
        langShow = !langShow;
    });

    var homeGallery = $('#c35 img');
    for (var i = 0; i < homeGallery.length; i++) {
        $(homeGallery[i]).fadeTo('fast', 0.3);
    }
    */


    $('.c83').delegate("li", "click", function () {

        if ($($(this).get(0).children[0]).css('display') == 'none') {
            $($(this).get(0).children[0]).fadeIn('fast');
            $($(this).get(0)).addClass('c84');
            $($(this).get(0)).css('background-image', 'url(/content/images/shared/r42.gif)');
        } else {
            $($(this).get(0).children[0]).fadeOut('fast');
            $($(this).get(0)).removeClass('c84');
            $($(this).get(0)).css('background-image', 'url(/content/images/shared/r41.gif)');
        }


    });

    $('#c35').delegate("img", "mouseover", function () {
        $(this).fadeTo('slow', 1);
    });

    $('#c35').delegate("img", "mouseout", function () {
        $(this).fadeTo('fast', .3);
    });

    $('#m10').mouseover(function () {
        $('#c60').fadeIn('slow');
    });
    $('#c60').mouseleave(function () {
        $('#c60').fadeOut('fast');
    });


    $('#c63').click(function () {
        window.location.href = '/' + lang;
    });

    $('#c78').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
    });

    $('.c88').delegate("", "click", function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
    });



    var c4Index = 80;
    setInterval(function () {
        var ilang = lang == 'fa' ? 'fa-IR' : 'en-US';
        $('#c4').css('background-image', 'url(/content/images/' + ilang + '/r' + c4Index + '.jpg)');

        c4Index++;
        if (c4Index > 83)
            c4Index = 80;

    }, 3000);

});