﻿var animatedBtns=new Array();
var gal;

function switchCss(cssFile)
{
  var lnk=document.getElementsByTagName("link")[0];
  lnk.setAttribute("href", "./css/"+cssFile+".css");
}
function izmeriEkran()
{
  alert(window.screen.width+" x "+window.screen.height);
}
function loadFigure(divId, fImg, posX, posY)
{
  var img=document.createElement("img");
  img.src="./img/"+fImg;
  var div=document.getElementById(divId);
  div.appendChild(img);
  div.style.left=posX;
  div.style.top=posY;
  }
function initNavBtns()
{
  //izmeriEkran();
  var i, imgEl, navDiv;
  for(i=0;i<animatedBtns.length;i++)
  {
    imgEl=document.createElement("img");
    imgEl.src="./img/"+animatedBtns[i][0];
    animatedBtns[i][0]=imgEl;
    imgEl=document.createElement("img");
    imgEl.src="./img/"+animatedBtns[i][1];
    imgEl.style.display="none";
    animatedBtns[i][1]=imgEl;
    navDiv=document.getElementById("navBtn"+i);
    navDiv.appendChild(animatedBtns[i][0]);
    navDiv.appendChild(animatedBtns[i][1]);
    navDiv.onmousedown=shwImg1;
    navDiv.onmouseup=shwImg2;
    //navDiv.name=animatedBtns[i][2];
  }
}
function shwImg1()
{
  this.childNodes[0].style.display="none";
  this.childNodes[1].style.display="";
}
function shwImg2()
{
  this.childNodes[1].style.display="none";
  this.childNodes[0].style.display="";
  var newLoc="./"+
             animatedBtns[this.id.replace(/\D+/, "")][2]+
             ".html";
  document.location=newLoc;
}
function quickLink(trenutnaStr)
{
  var lnks=Array
  (
    Array("Afričke kikice", "kikice"),
    Array("Nadogradnja kose", "nadogradnja"),
    Array("Dredovi", "dredovi"),
    Array("Riblje kosti", "ribljekosti"),
    Array("Trepavice", "trepavice"),
    Array("Studio", "studio")
  )
  var div=document.getElementById("quickLink");
  var i, spn;
  for(i=0;i<lnks.length;i++)
  {
    if(lnks[i][1]!=trenutnaStr)
    {
      spn=document.createElement("span");
      spn.className="quickLink";
      spn.id=lnks[i][1];
      spn.appendChild(document.createTextNode(lnks[i][0]));
      spn.onclick=qckJmp2page;
      div.appendChild(spn);
    }
  }
  var img=document.createElement("img");
  img.src="./img/naslov_"+trenutnaStr+".gif";
  div=document.getElementById("naslov");
  div.appendChild(img);
}
function qckJmp2page()
{
  var newLoc="./"+this.id+".html";
  document.location=newLoc;
}
function init_index()
{
  var div=document.getElementById("telefon");
  imgEl=document.createElement("img");
  imgEl.src="./img/telefon.gif";
  div.appendChild(imgEl);
  loadFigure("figura", "figura_bkgnd1024.jpg", 540, 20);
  switchCss('style1024x768')
  div.appendChild(imgEl);
}
function init_dredovi()
{
  quickLink("dredovi");
  loadFigure("figura", "figura_dredovi1024.jpg", 540, 20);
  switchCss('style1024x768');
}
function init_ribljekosti()
{
  quickLink("ribljekosti");
  loadFigure("figura1", "figura1ribljekosti1024.jpg", 540, 20);
  //loadFigure("figura2", "figura2ribljekosti1024.gif", 350, 320);
  switchCss('style1024x768');
}
function init_trepavice()
{
  quickLink("trepavice");
   //loadFigure("figura1", "figuraltrepavice1024.jpg", 540, 20);
  switchCss('style1024x768');
}
function init_kikice()
{
  quickLink("kikice");
  loadFigure("figura1", "figura1kikice1024.jpg", 540, 20);
  //loadFigure("kikice_razne", "kikice_razne.gif", 40, 540);
  switchCss('style1024x768');
}
function init_nadogradnja()
{
  quickLink("nadogradnja");
  loadFigure("figura", "figura_nadogradnja1024.jpg", 540, 20);
  switchCss('style1024x768');
}
function init_studio()
{
  quickLink("studio");
  loadFigure("figura1", "figura1studio1024.jpg", 540, 20);
  switchCss('style1024x768');
}
function gallery(ukupnoSlika, horCount, verCount, baseDir)
{
  this.ukupnoSlika=ukupnoSlika;
  this.horCount=horCount;
  this.verCount=verCount;
  this.baseDir="./img/"+baseDir;
  this.thumbnails=new Array();
  this.pageCount=1;
  this.curPage=1;
  this.thnsPerPage=horCount*verCount;

  var i, o, thnImg;

  this.goPrev=function()
  {
    this.curPage--;
    if(this.curPage==1)
      document.getElementById("gNavPrev").style.display="none";
    document.getElementById("qnavForw").style.display="";
    this.showPage();
  }
  this.goBack=function()
  {
    var newLoc="./"+baseDir+".html";
    document.location=newLoc;
  }
  this.goForw=function()
  {
    this.curPage++;
    if(this.curPage==this.pageCount)
      document.getElementById("qnavForw").style.display="none";
    document.getElementById("gNavPrev").style.display="";
    this.showPage();
  }
  this.showPage=function()
  {
    var i, o;
    for(i=1;i<=this.ukupnoSlika;i++)
      this.thumbnails[i].style.display="none";
    for(i=1;i<=this.thnsPerPage;i++)
    {
      o=((this.curPage-1)*this.thnsPerPage)+i;
      if(o<=this.ukupnoSlika)
        this.thumbnails[o].style.display="";
    }
    hidePict();
  }

  for(i=1, o=0;i<=this.ukupnoSlika;i++)
  {
    if(o==this.thnsPerPage)
    {
      this.pageCount++;
      o=1;
    }
    else o++;

    thnImg=document.createElement("img");
    thnImg.src=this.baseDir+"/m"+i+".jpg";
    thnImg.id=this.baseDir+"/v"+i+".jpg";
    thnImg.onclick=enlargePict1024;
    thnImg.className="galleryThumb"+o;
    thnImg.title="Klikni i povećaj sliku";

    this.thumbnails[i]=thnImg;
    document.body.appendChild(thnImg);
  }

  document.getElementById("gNavPrev").style.display="none";
  if(this.pageCount>1)
    document.getElementById("qnavForw").style.display="";
  else
    document.getElementById("qnavForw").style.display="none";

  switchCss('style1024x768');
  this.showPage();
  document.getElementById("imgBig").style.display="none";
  document.getElementById("imgBig").appendChild(document.createElement("img"));
  document.getElementById("imgBig").title="Klikni i smanji sliku";

}
function enlargePict1024()
{
  var div=document.getElementById("imgBig");
  div.firstChild.src=false;
  div.firstChild.src=this.id;
  div.style.display="";
  var nX=(1024-div.firstChild.width)/2;
  div.style.left=nX;
  div.style.width=div.firstChild.width;
  div.style.height=div.firstChild.height;
}
function hidePict()
{
  var div=document.getElementById("imgBig");
  div.style.display="none";
}