﻿var Browser = {
    Version: function() {
        var version = 999; // we assume a sane browser
        if (navigator.appVersion.indexOf("MSIE") != -1)
        // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}

function wOpen(name, src) {
    window.open(src + "&close=yes", name, "width=700, height=700, scrollbars=yes, toolbar=yes");
}

function fillsrch() {
    if (getQueryVariable('srch') && getQueryVariable('srch') != "")
        document.getElementById('srch1').value = getQueryVariable('srch');
}

function srchEnt() {
    if (event.keyCode == 13) {
        srch();
        return false;
    }
}

function srch() {
    if (document.getElementById('srch1').value.indexOf("Pretr") < 0)
        location.href = "Default.aspx?srch=" + document.getElementById('srch1').value;
}

function load() {
    if (document.all)
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    $('#m1').mousemove(function(event) {
        mmove("1");
    });
    $('#m2').mousemove(function(event) {
        mmove("2");
    });
    $('#m3').mousemove(function(event) {
        mmove("3");
    });
    $('#m4').mousemove(function(event) {
        mmove("4");
    });
    $('#m5').mousemove(function(event) {
        mmove("5");
    });

    mmove("");

}

function mmove(id) {

    var x;
    var strImgGS = "img/grayscale/";
    var strImg = "img/";

    if (id != "") {

        unmove(id);

        document.getElementById("mh" + id).className = "mhsel";
        document.getElementById("mb" + id).className = "mbsel";

        $("#mb" + id).slideDown("slow");

        if (id == "1")
            document.getElementById("m1").style.background = "url(" + strImg + "navigacija_kastav" + ".jpg)";
        else
            document.getElementById("m1").style.background = "url(" + strImgGS + "navigacija_kastav" + ".jpg)";

        if (id == "2")
            document.getElementById("m2").style.background = "url(" + strImg + "navigacija_grad" + ".jpg)";
        else
            document.getElementById("m2").style.background = "url(" + strImgGS + "navigacija_grad" + ".jpg)";

        if (id == "3")
            document.getElementById("m3").style.background = "url(" + strImg + "navigacija_kultura" + ".jpg)";
        else
            document.getElementById("m3").style.background = "url(" + strImgGS + "navigacija_kultura" + ".jpg)";

        if (id == "4")
            document.getElementById("m4").style.background = "url(" + strImg + "navigacija_gospodarstvo" + ".jpg)";
        else
            document.getElementById("m4").style.background = "url(" + strImgGS + "navigacija_gospodarstvo" + ".jpg)";

        if (id == "5")
            document.getElementById("m5").style.background = "url(" + strImg + "navigacija_dokumentacija" + ".jpg)";
        else
            document.getElementById("m5").style.background = "url(" + strImgGS + "navigacija_dokumentacija" + ".jpg)";

    }
    else {
        document.getElementById("m1").style.background = "url(" + strImgGS + "navigacija_kastav" + ".jpg)";
        document.getElementById("m2").style.background = "url(" + strImgGS + "navigacija_grad" + ".jpg)";
        document.getElementById("m3").style.background = "url(" + strImgGS + "navigacija_kultura" + ".jpg)";
        document.getElementById("m4").style.background = "url(" + strImgGS + "navigacija_gospodarstvo" + ".jpg)";
        document.getElementById("m5").style.background = "url(" + strImgGS + "navigacija_dokumentacija" + ".jpg)";
        unmove("");
    }
}

function unmove(n) {
    for (x = 1; x <= 5; x++) {
        if (x != n) {
            if (x == 1 || x == 3 || x == 5)
                document.getElementById("mh" + x).className = "mh135";
            else
                document.getElementById("mh" + x).className = "mh";

            document.getElementById("mb" + x).className = "mb";
            $("#mb" + x).slideUp("slow");
        }
    }
}

function mm_hide(e) {
    return;
    if (!e) var e = window.event;
    var tg = (window.event) ? e.srcElement : e.target;
    if (tg.nodeName == 'A') return;
    if (tg.nodeName == 'DIV') return;
    if (tg.nodeName == 'INPUT') return;
    if (tg.nodeName == 'B') return;

    var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
    if (!reltg) return;
    try {
        while (reltg != tg && reltg.nodeName != 'BODY')
            reltg = reltg.parentNode
    }
    catch (ex) { }
    if (reltg == tg)
        return;
    else {
        mmove('');
    }
}



function EndRequestHandler() {
    //if(window.location.search.substring(1) != "")
    //	top.location.hash = 'atop';
}

function slideShow() {

    //Set the opacity of all images to 0  
    $('#gallery a').css({ opacity: 0.0 });

    //Get the first image and display it (set it to full opacity)  
    $('#gallery a:first').css({ opacity: 1.0 });

    //Set the caption background to semi-transparent  
    $('#gallery .caption').css({ opacity: 1.0 });

    //Resize the width of the caption according to the image width  
    $('#gallery .caption').css({ width: $('#gallery a').find('img').css('width') });

    //Get the caption of the first image from REL attribute and display it  
    $('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
    .animate({ opacity: 1.0 }, 400);

    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds  
    setInterval('gallery()', 6000);

}

function gallery() {

    //if no IMGs have the show class, grab the first image  
    var current = ($('#gallery a.show') ? $('#gallery a.show') : $('#gallery a:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image  
    var next = ((current.next().length) ? ((current.next().hasClass('caption')) ? $('#gallery a:first') : current.next()) : $('#gallery a:first'));

    //Get next image caption  
    var caption = next.find('img').attr('rel');

    //Set the fade in effect for the next image, show class has higher z-index  
    next.css({ opacity: 0.0 })
    .addClass('show')
    .animate({ opacity: 1.0 }, 1000);

    //Hide the current image  
    current.animate({ opacity: 0.0 }, 1000)
    .removeClass('show');

    //Set the opacity to 0 and height to 1px  
    $('#gallery .caption').animate({ opacity: 0.0 }, { queue: false, duration: 0 }).animate({ height: '1px' }, { queue: true, duration: 300 });

    //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect  
    $('#gallery .caption').animate({ opacity: 1.0 }, 100).animate({ height: '30px' }, 500);

    //Display the content  
    $('#gallery .content').html(caption);

}  