/*$(function() {
   setTimeout(function() {
      $("div.banner_728x90").css('background-image', 'none');
   } , 5000);
   setTimeout(function() {
      $("div#BANNER_160x600").css('background-image', 'none');
   } , 5000);
   setTimeout(function() {
      $("div.d_banner614").css('background-image', 'none');
   } , 5000);
   setTimeout(function() {
      $("div#d_content div#d_right div.d_banner div").css('background-image', 'none');
   } , 5000);
   setTimeout(function() {
      $("div.d_banner468").css('background-image', 'none');
   } , 5000);
   setTimeout(function() {
      $("div.d_banner130").css('background-image', 'none');
   } , 5000);
   setTimeout(function() {
      $("div.clanek_oglas").css('background-image', 'none');
   } , 5000);
});*/

$(function() {
   $("div#MENU a.not_selected").mouseenter(function() {
      $(this).css('color', '#4e4e4e');
   });
   $("div#MENU a.not_selected").mouseleave(function() {
      $(this).css('color', '#818189');
   });
   
   $("div#MENU a.home_button_not_selected").mouseenter(function() {
      $(this).css('background-image', 'url("/assets/delo_v3/img/home_button_dark.png")');
   });
   $("div#MENU a.home_button_not_selected").mouseleave(function() {
      $(this).css('background-image', 'url("/assets/delo_v3/img/home_button2.png")');
   });
});

$(function() {
   $( ".DATEPICKER" ).datepicker({
      changeMonth: true,
      changeYear: true,
      yearRange: '1910:2012'
   });
});

// begin borza
var activeBorza = 1;
var moving = false;
function changeWait(someInt) {
   if (someInt==activeBorza) {
      $(".scroller"+someInt+"wait").hide();
      $(".scroller"+someInt).show();
      $(".d_leftarrow").hide();
      $(".d_rightarrow").show();
   }
}
function borzaNext() {
   var scroller;
   if (!moving) {
      $("a.d_rightarrow").each(function() {
         if ($(this).parent().css('display')!="none") {
            if ($(this).css('display')=="none") {
               newBorza = parseInt(activeBorza)+1;
               if (newBorza==4) {
                  newBorza=1;
               }
               $("div#d_content div#d_right div.d_borza div.d_buttons a[rel="+newBorza+"]").each(function() {
                  handleButtonClick(this);
               });

            } else {
               handleRightArrowClick(this);
            }
         }
      });
   }
}

function handleButtonClick(something) {
   $("div#d_content div#d_right div.d_borza div.d_buttons a").removeClass("d_selected");
   $(".d_scroller").hide();
   $(".scroller"+$(something).attr('rel')+"wait").show();
   $(something).addClass("d_selected");
   setTimeout("changeWait("+$(something).attr('rel')+");",1000);
   activeBorza=$(something).attr('rel');
   $("div.d_scrolldiv").css({
      'left':0
   });

   $("div#d_content div#d_right div.d_borza div.d_scroller").each(function() {
      $(this).data("current",0);
      $(this).data("max",$(this).find("div.d_tecaji").size());
   });
}

function handleRightArrowClick(something) {
   if (!moving) {
      moving=true;
      current = $(something).parent().data("current");
      max = $(something).parent().data("max");
      if (current<max) {
         newleft = parseInt($(something).parent().find("div.d_scrollcontainer div.d_scrolldiv").css('left'))-170;
         $(something).parent().find("div.d_scrollcontainer div.d_scrolldiv").animate({
            'left':newleft
         },function() {
            moving=false;
         });
         current++;
      }
      if (current>0) {
         $(something).parent().find("a.d_leftarrow").show();
      }
      if (current==max-1) {
         $(something).hide();
      }
      $(something).parent().data("current",current);
   }
}
//end borza
function vIE(){
   return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
}

$(window).load(function(){
   var content_holder_height = $("div#CONTENT_HOLDER").height()
   $("a.background_advertising_link_small").height(content_holder_height);
   $("a.background_advertising_link").height(content_holder_height);
});

$(document).ready(function() {

   //interval za avtomaticno premikanje borze (3 sekunde)
   //interval = setInterval("borzaNext()",3000);

   //eventi za zgornjo modro pasico
   $("div.d_bluebackground div.d_navigation div.d_left a").click(function() {
      $("div.d_bluebackground div.d_navigation div.d_left a").removeClass("d_red");
      $(this).addClass("d_red");
      $("div.d_hiddenheader div.d_headercontent div.d_box").hide();
      $("div.d_hiddenheader div.d_headercontent div#box"+$(this).attr('rel')).show();
      $("div.d_hiddenheader").slideDown();
   });

   //najbolj brano & najbolj komentirano
   $("div#d_content div#d_right div.BUBBLE1 div.d_bubble a").click(function () {
      if (!$(this).parent().hasClass("selected")) 
      {
         $("div.BUBBLE1 div.d_bubble").removeClass('selected').addClass('not_selected');
         $(this).parent().removeClass('not_selected').addClass('selected');
         $("div.BUBBLE1 div.d_newscontrol").hide();
         $("div.BUBBLE1 #news"+$(this).attr('rel')).show();
      }
   });
   
   //najbolj brano & najbolj komentirano
   $("div#d_content div#d_right div.BUBBLE2 div.d_bubble a").click(function () {
      if (!$(this).parent().hasClass("selected")) 
      {
         $("div.BUBBLE2 div.d_bubble").removeClass('selected').addClass('not_selected');
         $(this).parent().removeClass('not_selected').addClass('selected');
         $("div.BUBBLE2 div.d_newscontrol").hide();
         $("div.BUBBLE2 #news"+$(this).attr('rel')).show();
      }
   });

   $("div#d_content div#d_right div.BUBBLE3 div.d_bubble a").click(function () {
      if (!$(this).parent().hasClass("selected")) 
      {
         $("div.BUBBLE3 div.d_bubble").removeClass('selected').addClass('not_selected');
         $(this).parent().removeClass('not_selected').addClass('selected');
         $("div.BUBBLE3 div.d_newscontrol").hide();
         $("div.BUBBLE3 #news"+$(this).attr('rel')).show();
      }
   });

   //eventi za gumb vec
   $("a.d_more").click(function() {
      if ($(this).hasClass("d_active")) {
         $(this).parent().children(".d_dropdown").slideUp(500, function() {
            $(this).parent().children(".d_more").removeClass("d_active");
         });
      } else {
         $(this).addClass("d_active");
         $(this).parent().children(".d_dropdown").slideDown(500);
      }
   });


   //eventi za navigacijo (na hover se spremeni class in spremeni class levemu siblingu zaradi temne modre crte, prikaze se tista podnavigacija kot je navedena v rel atributu anchorja
   $("div#d_navigation a.d_button").mouseover(function() {
      if (!$(this).hasClass("d_active")) 
      {
         $(this).addClass("d_hoover");
      } 
   });
   
   $("div#d_navigation a.d_button").mouseleave(function() {
      $(this).removeClass("d_hoover");      
   });
   
   
   //event za input boxe
   $("input:text").each(function ()
   {
      if(this.className != "d_arhivsearch"){
         // store default value
         var v = this.value;

         $(this).blur(function ()
         {
            // if input is empty, reset value to default 
            if (this.value.length == 0) this.value = v;
         }).focus(function ()
         {
            // when input is focused, clear its contents
            if(this.value == v){
               this.value = "";
            }
         });
         $(this).removeAttr("disabled");
      }
   });

   //priprava spremenljivk za borzo
   $("div#d_content div#d_right div.d_borza div.d_scroller").each(function() {
      $(this).data("current",0);
      $(this).parent().find(".d_leftarrow").hide();
      $(this).data("max",$(this).find("div.d_tecaji").size());
   });

   //handler za klik na levo puscico
   $("div#d_content div#d_right div.d_borza div.d_scroller a.d_leftarrow").click(function() {
      if (!moving) {
         moving=true;
         current = $(this).parent().data("current");
         max = $(this).parent().data("max");
         if (current>0) {
            newleft = parseInt($(this).parent().find("div.d_scrollcontainer div.d_scrolldiv").css('left'))+170;
            $(this).parent().find("div.d_scrollcontainer div.d_scrolldiv").animate({
               'left':newleft
            }, function() {
               moving = false;
            });
            current--;
         }
         if (current==0) {
            $(this).hide();
         }
         if (current<max-1) {
            $(this).parent().find("a.d_rightarrow").show();
         }
         $(this).parent().data("current",current);
         
      }
   });

   //handler za klik na desno puscico, zawrappani so zato ker moramo lociti med dejanskim klikom in js-invoked klikom, ki ga spro�a interval
   $("div#d_content div#d_right div.d_borza div.d_scroller a.d_rightarrow").click(function() {
      handleRightArrowClick(this);
      
   });

   //handler za klik na okrogle gumbe pri borzi, zawrappan je zato ker moramo lociti med dejanskim klikom in js-invoked klikom, ki ga spro�a interval
   $("div#d_content div#d_right div.d_borza div.d_buttons a").click(function() {
      handleButtonClick(this);
      
   });

   //nastavimo zaceten interval za prikaz naslova prve borze
   setTimeout("changeWait(1)",1000);


   //klik kamorkoli na body izven modre pasice zapira modro pasico
   /*var mouseinside = false;
   var mousehidden = false;
   $("div.d_bluebackground").mouseenter(function () {
      mouseinside=true;

   });
   $("div.d_bluebackground").mouseleave(function () {
      mouseinside=false;
   });
   $("div.d_hiddenheader").mouseenter(function () {
      mousehidden=true;

   });
   $("div.d_hiddenheader").mouseleave(function () {
      mousehidden=false;
   });
   $("body").click(function() {
      if (!mouseinside&&!mousehidden) {
         $("div.d_hiddenheader").slideUp();
      }
   });*/

   //handlerji za klik pri anketi
   $(".d_male").click(function() {
      $(".formsex").val("male");
      $.post("poll-results.html", $(".formpoll").serialize(),
      function(data){
         $(".d_poll").html(data);
      }, "html");
   });
   $(".d_female").click(function() {
      $(".formsex").val("female");
      $.post("poll-results.html", $(".formpoll").serialize(),
      function(data){
         $(".d_poll").html(data);
      }, "html");
   });


   //resizing
   /*$(window).load(function(){
        var maxheight_b = $("#B1").height();
        if ($("#MainTopic").height()>maxheight_b) {
            maxheight_b = $("#MainTopic").height();
        }
        $("#B1").height(maxheight_b+1);
        $("#MainTopic").height(maxheight_b);

        var b2_height = $("#B2").height();
        var b3_height = $("#B3").height();
        // +1 in comments height is because of that b2 and b3 have borders, so 2 together and comments have only 1 border
        var title_height = $(".d_category_titile_blue").height();
        var comments_height = $("#COMMENTS").height()+title_height;
        var comments_height_alone = $("#COMMENTS").height();
        if(b2_height + b3_height > comments_height)
        {
            $("#COMMENTS").height(b2_height + b3_height-title_height);
        }
        else if(b2_height + b3_height < comments_height)
        {
            if(comments_height % 2 != 0)
            {
                comments_height++;
                // +1 in comments height is because of that b2 and b3 have borders
                $("#COMMENTS").height(comments_height_alone+1);
            }
         
            var b2_b3_split_height = comments_height / 2;
            $("#B2").height(b2_b3_split_height);
            $("#B3").height(b2_b3_split_height+1);
        }

        var maxheight_d = $("#B4").height();
        if ($("#D1").height()>maxheight_d) {
            maxheight_d = $("#D1").height();
        }
        $("#B4").height(maxheight_d);
        $("#D1").height(maxheight_d);

        var maxheight_e = $("#B5").height();
        if ($("#D2").height()>maxheight_e) {
            maxheight_e = $("#D2").height();
        }
        $("#B5").height(maxheight_e);
        $("#D2").height(maxheight_e);

        var maxheight_f = $("#B6").height();
        if ($("#D3").height()>maxheight_f) {
            maxheight_f = $("#D3").height();
        }
        $("#B6").height(maxheight_f);
        $("#D3").height(maxheight_f);

        var maxheight_g = $("div.d_linksleft").height();
        if ($("div.d_linksright").height()>maxheight_g) {
            maxheight_g = $("div.d_linksright").height();
        }
        $("div.d_linksleft").height(maxheight_g);
        $("div.d_linksright").height(maxheight_g);
    });*/
        
   //resizing
   /*$(window).load(function(){
      var height_left = $("#B1").height()+$("#B2").height()+$("#B3").height()+$("#B4").height()+$("#B5").height()+$("#B6").height();
      var height_right = $("#MainTopic").height()+$("#COMMENTS").height()+$(".d_category_title_blue").height()+$("#D1").height()+$("#D2").height()+$("#D3").height();
      var razlika = height_right-height_left;
      var razmik = 0;
      var b_height = 0;
      if(razlika > 0){
         razmik =razlika/4;
      }
      b_height = $("#B1").height();
      $("#B1").height(b_height+razmik);
      b_height = $("#B2").height();
      $("#B2").height(b_height+razmik);
      b_height = $("#B3").height();
      $("#B3").height(b_height+razmik);
      b_height = $("#B4").height();
      $("#B4").height(b_height+razmik);
      b_height = $("#B5").height();
      $("#B5").height(b_height+razmik);
   });*/
   

   
   $(".d_otherlinks").each(function() {
      if ($(this).parent().children(".d_othernews").height()>($(this).height())) {
         maxheight=0;
         $(this).parent().children(".d_otherlinks").each(function() {
            if ($(this).height()>maxheight) {
               maxheight=$(this).height();
            }
         });
         if ($(this).parent().children(".d_othernews").height()>maxheight) {
            maxheight=$(this).parent().children(".d_othernews").height();
         }
         $(this).height(maxheight);
      } else {
         maxheight=0;
         $(this).parent().children(".d_otherlinks").each(function() {
            if ($(this).height()>maxheight) {
               maxheight=$(this).height();
            }
         });
         $(this).height(maxheight);
      }
   });

   // POZOR: če damo divu d_split še class d.alignhalvessubpage se vsi placeholderji alignajo AMPAK to deluje samo če jih je na obeh straneh enako število
   $("div.d_alignhalvessubpage").each(function() {
      var elementscounter=0;
      var righthalf = $(this).children(".d_half").eq(1).children("div");
      $(this).children(".d_half").eq(0).children("div").each(function() {
         maxheight=$(this).height();
         if (righthalf.eq(elementscounter).height()>maxheight) {
            maxheight=righthalf.eq(elementscounter).height();
         }
         $(this).height(maxheight);
         righthalf.eq(elementscounter).height(maxheight);
         elementscounter++;
      });

   });


   //koda za IZ ARHIVA: SLOVENIJA
   $("div.d_phase1 a.d_starejse").click(function() {
      $("div.d_archivephase1").hide();
      $("div.d_archivephase2").show();
   });

   $("div.d_phase2 a.d_novejse").click(function() {
      $("div.d_archivephase2").hide();
      $("div.d_archivephase1").show();
   });
   $("div.d_phase2 a.d_starejse").click(function() {
      $("div.d_archivephase2").hide();
      $("div.d_archivephase3").show();
   });

   $("div.d_phase3 a.d_novejse").click(function() {
      $("div.d_archivephase3").hide();
      $("div.d_archivephase2").show();
   });
    
   var maxheight_fotozgodba1 = $("div#G1 div.item_holder").height();
   if ($("div#G2 div.item_holder").height()>maxheight_fotozgodba1) {
      maxheight_fotozgodba1 = $("div#G2 div.item_holder").height();
   }
   if ($("div#G3 div.item_holder").height()>maxheight_fotozgodba1) {
      maxheight_fotozgodba1 = $("div#G3 div.item_holder").height();
   }
   $("div#G1 div.item_holder").height(maxheight_fotozgodba1);
   $("div#G2 div.item_holder").height(maxheight_fotozgodba1);
   $("div#G3 div.item_holder").height(maxheight_fotozgodba1);
   
   var maxheight_fotozgodba2 = $("div#G4 div.item_holder").height();
   if ($("div#G5 div.item_holder").height()>maxheight_fotozgodba2) {
      maxheight_fotozgodba2 = $("div#G5 div.item_holder").height();
   }
   if ($("div#G6 div.item_holder").height()>maxheight_fotozgodba2) {
      maxheight_fotozgodba2 = $("div#G6 div.item_holder").height();
   }
   $("div#G4 div.item_holder").height(maxheight_fotozgodba2);
   $("div#G5 div.item_holder").height(maxheight_fotozgodba2);
   $("div#G6 div.item_holder").height(maxheight_fotozgodba2);  
});

function resetPollRadios(count){
   for(i = 0; i < count; i++){
      elementName = 'POLLc1_' + i;
      $("input#" + elementName).click(function() {
         $("a.d_female_none").addClass("d_female") ;
         $("a.d_female").removeClass("d_female_none") ;
         $("a.d_male_none").addClass("d_male") ;
         $("a.d_male").removeClass("d_male_none") ;
      });
      if(document.getElementById(elementName).checked){
         document.getElementById(elementName).checked = false;
      }
   }
}

function redirect_to_in(url, seconds)
{
   //setTimeout("window.location='"+url+"'", seconds);
   window.location=url;
}

function CheckUserLoginChecked()
{
   if(getCookie("user_login_info_c") == "true")
   {
      $("#remember_me").attr('checked', true);
   }
}

function facebookConnect(form, action){
   switch(action)
   {
      case "login":
         facebookLogin();
         break;
      case "logout":
         Odjava();
         break;
   }
}

href="/uporabnik/odjava"

function facebookLogin()
{      
   //alert('Connecting to facebook');
   function handleResponse(response){
      if(response.status == 'connected')
      {
         setCookie("facebook_connected", "true", 1);
         window.location.reload();
      }
   }
   FB.login(handleResponse,{
      perms:'user_about_me,user_birthday,user_hometown,user_interests,email,publish_stream'
   });
}

function Odjava()
{
   setCookie("facebook_connected", "false", 365);
   //alert('Disconnected to facebook');
   window.location = "/uporabnik/odjava";
}

function setCookie(c_name,value,exdays)
{
   var exdate=new Date();
   exdate.setDate(exdate.getDate() + exdays);
   var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
   document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
   var i,x,y,ARRcookies=document.cookie.split(";");
   for (i=0;i<ARRcookies.length;i++)
   {
      x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
      y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
      x=x.replace(/^\s+|\s+$/g,"");
      if (x==c_name)
      {
         return unescape(y);
      }
   }
}

function addToHomepage() {
   var title='Delo.si';
   var url='http://www.delo.si/';
   if(document.all)
      window.external.AddFavorite(url,title);
   else if(window.sidebar)
      window.sidebar.addPanel(title,url,"")
   else if(window.sidebar&&window.sidebar.addPanel)
      window.sidebar.addPanel(title,url,"");
}


function DisplayNewsTiskano(title, supertitle, source, date, intro, text, signature) {
   $("div#PremiumRelatedNewsTiskano div.title").text(title);
   $("div#PremiumRelatedNewsTiskano div.supertitle").text(supertitle);
   $("div#PremiumRelatedNewsTiskano div.source").text(source);
   $("div#PremiumRelatedNewsTiskano div.date").text(date);
   $("div#PremiumRelatedNewsTiskano div.intro").text(intro);
   $("div#PremiumRelatedNewsTiskano div.text").text(text);
   $("div#PremiumRelatedNewsTiskano div.signature").text(signature);
}
