var strHref = window.location.href

var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
            || this.searchVersion(navigator.appVersion)
            || "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i=0;i<data.length;i++)    {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
        {
            string: navigator.userAgent,
            subString: "Chrome",
            identity: "Chrome"
        },
        {     string: navigator.userAgent,
            subString: "OmniWeb",
            versionSearch: "OmniWeb/",
            identity: "OmniWeb"
        },
        {
            string: navigator.vendor,
            subString: "Apple",
            identity: "Safari",
            versionSearch: "Version"
        },
        {
            prop: window.opera,
            identity: "Opera"
        },
        {
            string: navigator.vendor,
            subString: "iCab",
            identity: "iCab"
        },
        {
            string: navigator.vendor,
            subString: "KDE",
            identity: "Konqueror"
        },
        {
            string: navigator.userAgent,
            subString: "Firefox",
            identity: "Firefox"
        },
        {
            string: navigator.vendor,
            subString: "Camino",
            identity: "Camino"
        },
        {        // for newer Netscapes (6+)
            string: navigator.userAgent,
            subString: "Netscape",
            identity: "Netscape"
        },
        {
            string: navigator.userAgent,
            subString: "MSIE",
            identity: "Explorer",
            versionSearch: "MSIE"
        },
        {
            string: navigator.userAgent,
            subString: "Gecko",
            identity: "Mozilla",
            versionSearch: "rv"
        },
        {         // for older Netscapes (4-)
            string: navigator.userAgent,
            subString: "Mozilla",
            identity: "Netscape",
            versionSearch: "Mozilla"
        }
    ],
    dataOS : [
        {
            string: navigator.platform,
            subString: "Win",
            identity: "Windows"
        },
        {
            string: navigator.platform,
            subString: "Mac",
            identity: "Mac"
        },
        {
               string: navigator.userAgent,
               subString: "iPhone",
               identity: "iPhone/iPod"
        },
        {
            string: navigator.platform,
            subString: "Linux",
            identity: "Linux"
        }
    ]

};
BrowserDetect.init();

function determineFirst(first, countImg, countVid, where, videoid, countRot, autoplay1){
        //0=first,1=countImg,2=countVid,3=where,4=videoid,5=countRot,6=autoplay
    //var d = new Date();
    newrc = "rc"+varsOther[where][3];
    rotators = dw_Rotator.col.length;
    if(autoplay1 == 1) {
        varsOther[where][6] = 1;
    }
    else{
        varsOther[where][6] = 0;
    }    
    if(first == 1){
        for(i=0;i<AllFotoArray[where].length;i++){
            if(AllTypeArray[where][i] == "image"){
                imageid = i;
                break;
            }
        }
        if(varsOther[where][1] == 1){
            rotimg = "";
            rotimgclone = "";
        }
        else{
            rotimg = " id='rotate_img" + varsOther[where][3] + "'";
            rotimgclone = " id='rotate_img" + varsOther[where][3] + "clone'";
        }
        if(BrowserDetect.browser == 'Firefox'){
            text = '<div id="video' + varsOther[where][3] + '" class="video"><a id="link' + varsOther[where][3] + '" href="/webadmin/files/novice/' + AllFotoArray[where][imageid] + '"><img ' + rotimg + ' src="/getimage.php?what=novice&image='+ AllFotoArray[where][imageid] +'&width=320&height=240" width="320px" height="240px" style="border: none;"><img ' + rotimgclone + ' src="/getimage.php?what=novice&image='+ AllFotoArray[where][imageid] +'&width=320&height=240" width="320px" height="240px" style="position: relative; top: -240px; left: 0px; border: none;"></a></div>';
        }
        else{
            text = '<div id="video' + varsOther[where][3] + '" class="video"><a id="link' + varsOther[where][3] + '" href="/webadmin/files/novice/' + AllFotoArray[where][imageid] + '"><img ' + rotimg + ' src="/getimage.php?what=novice&image='+ AllFotoArray[where][imageid] +'&width=320&height=240" width="320px" height="240px" style="border: none;"></a></div>';
        }
        text += '<div class="videotekst"><div id="videotekst'+varsOther[where][3]+'" class="podnapis">'+AllSubArray[where][imageid]+'</div></div>';
        text += '<div id="rc'+varsOther[where][3]+'" class="rotator_controls">';
        if(varsOther[where][1] > 1){
            text += '<div style="float: left;">';
            text += '<a href="javascript:void(0)" onclick="dw_Rotator.stop('+ varsOther[where][5] +');"><img src="/images2/ustavi.gif" alt="Ustavi" title="Ustavi" style="border: none"></a>&nbsp;&nbsp;';
            text += '<a href="javascript:void(0)" onclick="stopAllRotators(); dw_Rotator.restart('+ varsOther[where][5] +');"><img src="/images2/naprej.gif" alt="Naprej" title="Naprej" style="border: none"></a>';        
            text += '</div>';
        }
        if(varsOther[where][2] > 1){
            text += '<div style="float: right;"><font style="color: #90c741">Video: </font>';
            videoTid = 0;
            for(i=0;i<AllFotoArray[where].length;i++){
                if(AllTypeArray[where][i] == "video"){
                    videoTid++;
                    text += '<a href="javascript: determineFirst(0,'+ varsOther[where][1] +','+ varsOther[where][2] +','+ varsOther[where][3] +','+ i +','+ varsOther[where][5] +',1)">&nbsp;<b>' + videoTid + '<b>&nbsp;</a>';
                }    
            }
            text += '</div>';
       
        }        
        if(varsOther[where][2] == 1){
            if(varsOther[where][1] > 1){
                text += '<div style="float: right;">';
            }
            else{
                text += '<div style="float: left;">';
            }    
            
            for(i=0;i<AllFotoArray[where].length;i++){
                if(AllTypeArray[where][i] == "video"){
                    videoid = i;
                    break;
                }
            }
            text += '<a href="javascript: determineFirst(0,'+ varsOther[where][1] +','+ varsOther[where][2] +','+ varsOther[where][3] +','+ varsOther[where][4] +','+ varsOther[where][5] +',1)">Poglej video&nbsp;</a>';
            text += '</div>';
        }        
        text += '</div>';
        conteinerVar = "conteiner" + varsOther[where][3];
        document.getElementById(conteinerVar).innerHTML = text;
        //document.writeln(text);
        
        newrotimg = "rotate_img" + varsOther[where][3];
        if(document.getElementById(newrotimg) && varsOther[where][1] > 1){
            newrotator = eval("rotator" + varsOther[where][3]);
            if(varsOther[where][5] < 1){
                dw_Rotator.start(varsOther[where][5]);
            }    
        }
        
    }
 else{
        for(i=0;i<rotators;i++){
            if(i != rotgalerija){
                dw_Rotator.stop(i);
            }
        }        
        if(videoid == -1){
            for(i=0;i<AllFotoArray[where].length;i++){
                if(AllTypeArray[where][i] == "video"){
                    videoid = i;
                    break;
                }
            }
        }
        text = '<div id="video' + varsOther[where][3] + '" class="video">';
        text += '<div class="novideo">';
        text += insertVideo(varsOther[where][3],320,240,AllFotoArray[where][videoid],'autohide',varsOther[where][6]);
        text += '</div>';
        text += '</div>';
        text += '<div class="videotekst"><div id="videotekst'+varsOther[where][3]+'" class="podnapis">'+AllSubArray[where][videoid]+'</div></div>';
        text += '<div id="rc'+varsOther[where][3]+'" class="rotator_controls">';
        if(countImg > 0){
            text += '<a href="javascript: determineFirst(1,'+ varsOther[where][1] +','+ varsOther[where][2] +','+ varsOther[where][3] +',0,'+ varsOther[where][5] +',0)" style="float: left;">Poglej slike</a>';
        }
        if(countVid > 1){
            videoTid = 0;
            text += '<div align="right" style="float: right;"><font style="color: #90c741">Video: </font>';
            for(i=0;i<AllFotoArray[where].length;i++){
                if(AllTypeArray[where][i] == "video"){
                    videoTid++;
                    text += '<a href="javascript: determineFirst(0,'+ varsOther[where][1] +','+ varsOther[where][2] +','+ varsOther[where][3] +','+ i +','+ varsOther[where][5] +',1)">&nbsp;<b>' + videoTid + '&nbsp;</b>&nbsp;</a>';
                }    
            }
            text += '</div>';
        }
        text += '</div>';
        conteinerVar = "conteiner" + varsOther[where][3];
        document.getElementById(conteinerVar).innerHTML = text;
        //document.writeln(text);
    }   
        //0=first,1=countImg,2=countVid,3=where,4=videoid,5=countRot,6=autoplay
    //if(varsOther[where][1] < 2 && varsOther[where][2] < 2){
        //document.getElementById(newrc).style.height = "0px";
    //}    
}

function stopAllRotators(){
    for(i=0;i<dw_Rotator.col.length;i++){
        if(i != rotgalerija){
            dw_Rotator.stop(i);
        }
    }
}

function insertVideo(playerid, width, height, what, showbar, autoplay){
    
    var d = new Date();
    text1 = '<object id="player' + playerid + '" type="application/x-shockwave-flash" data="/swf/player_flv_maxi.swf" width="' + width + '" height="' + height + '">';
    text1 += '<param name="movie" value="/swf/player_flv_maxi.swf?' + d.getTime() + '">';
    text1 += '<param name="allowFullScreen" value="true">';
    text1 += '<param name="FlashVars" value="flv=/webadmin/files/novice/' + what + '&amp;width=' + width + '&amp;height=' + height + '&amp;autoload=1&amp;autoplay=' + autoplay + '&amp;margin=0&amp;showstop=1&amp;showvolume=1&amp;volume=150&amp;showtime=2&amp;showfullscreen=1&amp;playeralpha=75&amp;buttonovercolor=222222&amp;sliderovercolor=49963f&amp;showiconplay=1&amp;iconplaycolor=49963f&amp;iconplaybgalpha=75&amp;showplayer=' + showbar + '&amp;buffermessage=Nalagam _n_&amp;buffercolor=49963f&amp;showloading=autohide&amp;playertimeout=3000&amp;buffershowbg=0&amp;loadingcolor=49963f&amp;startimage=images2/video_back.jpg&amp;playercolor=7fc240&amp;slidercolor1=ceeea5&amp;slidercolor2=8fd739">';
    text1 += '</object>';
    return text1;
}

function insertVideo2(playerid, width, height, what, showbar, autoplay){
    
    var d = new Date();
    text1 = '<object id="player' + playerid + '" type="application/x-shockwave-flash" data="/swf/player_flv_maxi.swf" width="' + width + '" height="' + height + '">';
    text1 += '<param name="movie" value="/swf/player_flv_maxi.swf?' + d.getTime() + '">';
    text1 += '<param name="allowFullScreen" value="true">';
    text1 += '<param name="FlashVars" value="flv=/webadmin/files/novice/' + what + '&amp;width=' + width + '&amp;height=' + height + '&amp;autoload=1&amp;autoplay=' + autoplay + '&amp;margin=0&amp;showstop=1&amp;showvolume=1&amp;volume=150&amp;showtime=2&amp;showfullscreen=1&amp;playeralpha=75&amp;buttonovercolor=222222&amp;sliderovercolor=49963f&amp;showiconplay=1&amp;iconplaycolor=49963f&amp;iconplaybgalpha=75&amp;showplayer=' + showbar + '&amp;buffermessage=Nalagam _n_&amp;buffercolor=49963f&amp;showloading=autohide&amp;playertimeout=3000&amp;buffershowbg=0&amp;loadingcolor=49963f&amp;startimage=images2/video_back.jpg&amp;playercolor=7fc240&amp;slidercolor1=ceeea5&amp;slidercolor2=8fd739">';
    text1 += '</object>';
    document.getElementById('video').innerHTML = text1;
}

function displayImg(img,sub,id,naslov,datum,pos,width){
    novaWidth = "";
    if(parseInt(width) > 680) {novaWidth = " width=680px";}
    if(naslov != "fg"){
        where = "novice";
        if(naslov == "mediji"){
            text = '<table width="680px" style="margin: 0px auto 0px auto"><tr><td align="left" style="background: #e6f7cd">' + sub + '</td></tr></table><br>';    
        }
        else{
            text = '<table width="680px" style="margin: 0px auto 0px auto"><tr><td align="left"><h1 style="font-size: 12px; background: #dbf3bc;"><a href="index.php?page=1&subpage=' + id + '&add=galerija&first_pos=' + pos + '"><b>' + naslov + '</a></h1><font style="float: right;"><b>' + datum + '</b></font></td></tr><tr><td align="left" style="background: #e6f7cd">' + sub + '</td></tr></table><br>';
        }
    }
    if(naslov == "fg"){
        where = "foto";
        text = '<table width="680px" style="margin: 0px auto 0px auto"><tr><td align="left" style="background: #e6f7cd">' + sub + '</td></tr><tr><td align="right"><b>' + datum + '</b></td></tr></table><br>';
    }
    text += '<a href="/webadmin/files/' + where + '/' + img + '"><img id="wrapper" src="/webadmin/files/' + where + '/' + img + '" alt="' + sub + '" title="' + sub + '"' + novaWidth + '></a>';
    document.getElementById('img_display').innerHTML = text;
}

function displayVideo(video, sub, id, naslov, datum, pos){
    var d = new Date();
    if(naslov != "fg"){
        where = "novice";
        if(naslov == "mediji"){
            text = '<table width="680px" style="margin: 0px auto 0px auto"><tr><td align="left" style="background: #e6f7cd">' + sub + '</td></tr></table><br>';    
        }
        else{        
            text = '<table width="680px" style="margin: 0px auto 0px auto"><tr><td align="left"><h1 style="font-size: 12px; background: #dbf3bc;"><a href="index.php?page=1&subpage=' + id + '&add=galerija&first_pos=' + pos + '"><b>' + naslov + '</a></h1><font style="float: right;"><b>' + datum + '</b></font></td></tr><tr><td align="left" style="background: #e6f7cd">' + sub + '</td></tr></table><br>';    
        }
    }
    if(naslov == "fg"){
        where = "foto";    
        text = '<table width="680px" style="margin: 0px auto 0px auto"><tr><td align="left" style="background: #e6f7cd">' + sub + '</td></tr><tr><td align="right"><b>' + datum + '</b></td></tr></table><br>';
    }
    text += '<div class="video3"><br>';
    text += '<object id="player" style="border: 2px #7fc240 solid;" type="application/x-shockwave-flash" data="/swf/player_flv_maxi.swf" width="640" height="480"><br>';
    text += '<param name="movie" value="/swf/player_flv_maxi.swf?' + d.getTime() + '"><br>';
    text += '<param name="allowFullScreen" value="true"><br>';
    text += '<param name="FlashVars" value="flv=/webadmin/files/' + where + '/' + video + '&amp;width=640&amp;height=480&amp;autoload=1&amp;autoplay=1&amp;margin=0&amp;showstop=1&amp;showvolume=1&amp;volume=150&amp;showtime=2&amp;showfullscreen=1&amp;playeralpha=75&amp;buttonovercolor=222222&amp;sliderovercolor=49963f&amp;showiconplay=1&amp;iconplaycolor=49963f&amp;iconplaybgalpha=75&amp;showplayer=autohide&amp;buffermessage=Nalagam _n_&amp;buffercolor=49963f&amp;showloading=autohide&amp;playertimeout=3000&amp;buffershowbg=0&amp;loadingcolor=49963f&amp;playercolor=7fc240&amp;slidercolor1=ceeea5&amp;slidercolor2=8fd739"><br>';
    text += '</object>';
    text += '</div>';
    document.getElementById('img_display').innerHTML = text;
}

function openPersonal(where){
    personalState = 'V Stranki mladih Slovenije se zavezujemo, da bomo vaše osebne podatke uporabljali le za namene pošiljanja naših obvestil in jih bomo varovali v skladu z Zakonom o varovanju osebnih podatkov.<br>';
    document.getElementById(where).innerHTML = personalState;
    document.getElementById(where).style.cursor = "pointer";
    document.getElementById(where).title = "Zapri sporočilo o varovanju podatkov";
    document.getElementById(where).onclick = function(){
        document.getElementById(where).innerHTML = "";
    }
}

function getX(oNode){
    var x = 0;
    while (oNode) {
        x += oNode.offsetLeft;
        oNode = oNode.offsetParent;
    }
    return x;
}

function getY(oNode){
    var y = 0;
    while (oNode) {
        y += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    return y;
}

function left(what, x){
    document.getElementById(what).style.left = x + "px";
}

function top(what, y){
    document.getElementById(what).style.top = y + "px";
}

function preveriZapise()
    {
        if(document.frmPrijava.txtIme.value == "")
        {
            alert("Prosim, vpišite ime!");
            document.frmPrijava.txtIme.focus();
            return false;    
        }
        if(document.frmPrijava.txtPriimek.value == "")
        {
            alert("Prosim, vpišite priimek!");
            document.frmPrijava.txtPriimek.focus();
            return false;    
        }
        if(document.frmPrijava.txtRojen.value == "")
        {
            alert("Prosim, vpišite datum rojstva!");
            document.frmPrijava.txtRojen.focus();
            return false;    
        }
        if(document.frmPrijava.txtEPosta.value == "")
        {
            alert("Prosim, vpišite e-mail naslov!");
            document.frmPrijava.txtEPosta.focus();
            return false;    
        }
}

function preveriIskalnik() {
        if(document.iskalnik.iskalnikTekst.value.length < 3)
        {
            alert("Iskalni pojem naj bo dolg vsaj tri črke!");
            document.iskalnik.iskalnikTekst.focus();
            return false;    
        }
}

//getPage
function getPage(page,subpage,add,show,video,year){
    document.pageVars.page.value = page;
    document.pageVars.subpage.value = subpage;
    document.pageVars.add.value = add; 
    document.pageVars.show.value = show; 
    document.pageVars.video.value = video;
    document.pageVars.year.value = year; 
    document.pageVars.submit();
}

function validate_email(field, alerttxt){
    with (field) {
        apos = value.indexOf("@");
        dotpos = value.lastIndexOf(".");
        if (apos < 1 || dotpos - apos < 2) {
            alert(alerttxt);
            return false;
        }
        else {
            return true;
        }
    }
}

//checkform
function checkform(){
    if (validate_email(document.anketa.posta, "Prosim, vpišite vaš pravilni elektronski naslov.") == false) {
            document.anketa.posta.focus();
            return false;
        }
}

function getImageWidth(myImage) {
    var x, obj;
    if (document.layers) {
        var img = getImage(myImage);
        return img.width;
    } else {
        return getElementWidth(myImage);
    }
    return -1;
}

 function bookmark(url,title){
    if (window.sidebar){
        window.sidebar.addPanel(title, url,"");
    }
    if( window.external ){
        window.external.AddFavorite( url, title);
    }
 }