//------------------------------------------------------------------------------
//Nordea Page Initiator Class
//Code history:
//Oct 2007: Micha³ Nawrot - Original code autor

function PageInitiator(){
  //------------------
  //konstruktor
  
    if(jQuery("#content").height() > 800 && jQuery("#index").size() == 0)
  	  jQuery("#backToTopLink").css("visibility", "visible");//show();
    else
  	  jQuery("#backToTopLink").css("visibility", "hidden");//hide();
  
	//------------------
	//top menu initiator
	this.initTopMenu = function(elemId){
    jQuery("#"+elemId+" > li.login, #"+elemId+" > li.groups").each(
      function(i){
        
        var div = jQuery(this).find("li:first").before("<div class=\"tmbox\"></div>");
        jQuery(this).find("div").css("width", jQuery(this).width()+13+"px");
        if(jQuery(this).children("ul").width() < jQuery(this).width())
                jQuery(this).children("ul").css("width", (jQuery(this).width()+13)*1+"px"); 
        
        
        jQuery(this).hover(      
          function(event){                
              this.className += " mover";
              
              jQuery(this).children("ul").show(200);    
                         
          },            
          function(event){      
              this.className = this.className.substr(0,this.className.indexOf(' '));
              jQuery(this).children("ul").hide();
              var self = this;
              function tout(){
                if(self.className != "mover")
                  jQuery(self).children("ul").hide();
              }
              setTimeout(tout,200);
          }
        );
      }
    );
  }
  
  //--------------------
  //left menu initiator  
  this.initLeftMenu = function(elemId){
    jQuery("#"+elemId+" li").each(
      function(i){
        jQuery(this).css("z-index", (10000-i));
      }
    );
    jQuery("#"+elemId+" li.li_out").hover(      
      function(event){
          if(jQuery(this).parent().is("#"+elemId+""))
            jQuery("select").css("visibility","hidden");
          this.className = "li_over";
          jQuery(this).children("ul").show(200);    
          
      },            
      function(event){
          if(jQuery(this).parent().is("#"+elemId))          
            jQuery("select").css("visibility","visible");
          this.className = "li_out";
          jQuery(this).children("ul").hide();
          var self = this;
          function tout(){
            if(self.className != "li_over")
              jQuery(self).children("ul").hide();
          }
          setTimeout(tout,200);
      }
    );
    jQuery("#"+elemId+" li.li_out_end").hover(      
      function(event){
          this.className = "li_over_end";
      },          
      function(event){        
          this.className = "li_out_end";
      }
    );
  }
  
  this.initLinks = function(){
	  jQuery("a.target_blank").each(
		  function(i){
			this.target="_blank";
		  }
	  );
  }
  
}

//------------------------------------------------------------------------------
//on document is loaded
jQuery(document).ready(  
  function(){
	if($('.gold').length>0){
		$('#rightSide').addClass('gold');
	}
  
    var w = $('#content').width();
    $('#content').find('table').each(function(){
        var tw = $(this).width();
        var i = 1;
        while(tw>w && i<5){
            var orgFontSize = $(this).find('td').css('font-size');
            if(orgFontSize.indexOf("px") != -1){
                var fontSize = parseInt(orgFontSize);
                --fontSize;
                $(this).find('td').css('font-size', fontSize);
            }
            tw = $(this).width();
            ++i;
        }
    });
  
  	//Obsluga kotwic w UI Tabs
  	jumpOnLoad = function(){
	  	if(document.location.hash){
			var hash = new String(document.location.hash);
			var anchor_name = hash.replace('#', '');
		    jumpToAnchor(anchor_name);
		}
	}
  	var jumpToAnchor = function(anchor_name){
	    var anchor = $('a[name='+anchor_name+']');
	  	if(anchor.length){
	        anchor = $(anchor[0]);
	        var tab = anchor.parents('.ui-tabs-container.ui-tabs-hide').attr('id');
	        if(tab){
	            $('.ui-tabs-nav a[href=#'+tab+']').click();
	            //Okretka aby poczekac na otwarcie zakladki. Brak callback
            	setTimeout("var offset = $('a[name="+anchor_name+"]').offset(); $('html,body').animate({scrollTop: offset.top}, 200);",200);
	        }
	    }
	}
	
  	$('#leftMenuOut a[href^=#], .doc_contener a[href^=#]').click(function(){
	    var anchor_name = $(this).attr('href').replace('#', '');
	    jumpToAnchor(anchor_name);
	});
	
	setTimeout("jumpOnLoad();", 200);
	
	///////////////////////////////////////
    initiator = new PageInitiator();
    initiator.initLeftMenu("main_category_menu");
    initiator.initTopMenu("toolbar");      
    initiator.initLinks();
    if(jQuery.browser.msie){
      var ieVersion = parseFloat(jQuery.browser.version);
      if( ieVersion >= 5.5 &&  ieVersion < 6){
        jQuery("#wrapper").wrap("<center></center>");
        jQuery("link").each(
          function(i){
            if(this.href == "_items/css/screen.css")
              this.href = "_items/css/screen_ie55.css";
            if(this.href == "_items/css/index.css")
              this.href = "_items/css/index_ie55.css";
          }
        )
      }
    }
    
    $('ul#mainTabs a[href=http://www.market.nordea.pl/]').click(function(e){
		if(location.href == 'http://www.nordea.pl/index.html' 
		|| location.href ==  'http://www.nordea.pl/'
		|| location.href == 'http://nordea.pl/index.html'
		|| location.href ==  'http://nordea.pl/'
		|| location.href ==  'http://static24.nordea.blue.pl/index.html'
		|| location.href == 'http://static24.nordea.blue.pl/'
		) {
    		pageTracker._trackPageview('/external_market.nordea.pl');
    	}
    	
		if(location.href == 'http://www.nordea.pl/en/index.html'
		|| location.href == 'http://nordea.pl/en/index.html'
		|| location.href == 'http://static24.nordea.blue.pl/en/index.html'
		) {
    		pageTracker._trackPageview('/en/external_market.nordea.pl');
		}
    	
    });
  }
);

