﻿$(function(){
	

	$('#index-intro-promo').gallerify();
	 //alert(document.write(navigator.userAgent + "."));
	// easter egg :)
	$('<div id="worm"></div>').appendTo('#footer_sleeve').toggle(
		function(){
			$(this).parents('#footer_sleeve').animate({height:'835px'},{queue:false,duration:2000});
			$('html,body').animate({scrollTop:$('#footer_sleeve').offset().top + 865},{queue:false,duration:2000});
		}, function(){
			$(this).parents('#footer_sleeve').animate({height:'70px'},{queue:false,duration:2000});
		});
});

	jQuery.fn.gallerify = function() {
		return this.each(function(){
			var images = $('img.thumb-intro',this);
			//images.hide().css({opacity:0});
			//$(images[0]).show().css({opacity:1});
			
			images.hide();
			$(images[0]).show();
			//alert(images.length);
		    
			if (images.length > 1) 
			{   		    
				
				    $(this).after('<ul id="gallery_changer" style="cursor:pointer;" onclick="javascript: window.location='+"'/hr/ah_servisi/kreirajte_svoju_akciju.aspx'"+'"></ul>');
					var changer = $('+ul',this);
				    //alert(changer);
				    $('<span>')
				images.each(function()
				{
				    var numberLink = (images.index(this)+1).toString();
				    if (numberLink.length == 1) numberLink = '0' + numberLink;
				    $('<li style class="nav'+ numberLink +'" id= "nav'+ numberLink +'" onmouseover="javascript:rgcLink();" onmouseout="javascript:rgReload()"><a  href="'+ this.title +'">'+numberLink+'</a></li>').hover(showImage).appendTo(changer);
				    					
				 });
				 
				$('li:first',changer).addClass('first current');
				 $('</span>')
			}

			function showImage() {
				$(this).addClass('current').siblings().removeClass('current');
				var clicked = this;
				images.each(function(){
					if ($(this).is(':visible')) {
						//$(this).animate({opacity:0},100,function(){
						//$(this).animate({opacity:0},300,function(){
						    
							$(this).hide();
							
//							$(images[$(clicked).parent().children('li').index(clicked)]).css({display:'block'}).animate({opacity:1},200);
							$(images[$(clicked).parent().children('li').index(clicked)]).css({display:'block'});
						//});
					}
				});
				return false;
			}
			
			
			
		    });
		
		
	}
	
	function rgcLink()
	{
	       
			gc = document.getElementById("gallery_changer");
            gc.setAttribute("style","cursor:arrow;");
		    gc.setAttribute("onClick","");
			
	}
			
    function rgReload()
    {
        document.getElementById('t1').style.display ='block';   
		document.getElementById('t2').style.display ='none';
        document.getElementById('t3').style.display ='none';
        document.getElementById('t4').style.display ='none';
        
        
        
            
            var IE = detectBrowser();
            //alert(IE)
            if(IE==false){
                    sbs = document.getElementById("nav02");
                    sbs.setAttribute("class","nav02");
                    sbs = document.getElementById("nav03");
                    sbs.setAttribute("class","nav03");
                    sbs = document.getElementById("nav04");
                    sbs.setAttribute("class","nav04");
            } else if(IE==true) {
                      
                      //obj.setAttribute( 'className', 'special' ); 
                      sbs = document.getElementById("nav02");
                      sbs.setAttribute("className","nav02");
                        sbs = document.getElementById("nav03");
                        sbs.setAttribute("className","nav03");
                        sbs = document.getElementById("nav04");
                        sbs.setAttribute("className","nav04"); 
            }
        
        
        gc = document.getElementById("gallery_changer");
        gc.setAttribute("style","cursor:pointer;");
		gc.setAttribute("onClick","javascript: window.location='/hr/ah_servisi/kreirajte_svoju_akciju.aspx'");
        
    }
    
    function detectBrowser()
    {
        var browser=navigator.appName;
        //alert(browser);
        var b_version=navigator.appVersion;
        var version=parseFloat(b_version);
        if ((browser=="Microsoft Internet Explorer"))
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
    
    
      function sleep(naptime){
      naptime = naptime * 350;
      var sleeping = true;
      var now = new Date();
      var alarm;
      var startingMSeconds = now.getTime();
      //alert("starting nap at timestamp: " + startingMSeconds + "\nWill sleep for: " + naptime + " ms");
      while(sleeping){
         alarm = new Date();
         alarmMSeconds = alarm.getTime();
         if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false;}
      }      
      //alert("Wakeup!");
   }
	 