var $ie =  $.browser.msie;
var $ie7 = $.browser.msie && $.browser.version == 7;


function checkUri(){
  jQuery('.uri').each(function(){
    if(jQuery(this).attr('class').indexOf('checked') == -1){
      jQuery(this).click(function(){
        jQuery(this).addClass('checked');
        $url = jQuery(this).attr('href');
          //jQuery('#content').animate({'opacity': .3}, 400, function(){
            $uri = $url;
            if($url.substring(0, 1) == '/') $url = $url.substring(1, $uri.length);
            window.location.hash = $url;
            if($windowhash == $url) jQuery('#content').css('opacity', 1);
          //});
        return false;
      });
    }
  });
}

function loadContent($url){

  jQuery('#pagePreloader').show();
  $uri = $url;
  if($url[0] == '/') $url = $url.substring(1, $uri.length);
  
  var $html = $.ajax({
      url: '/ajax-anchor/'+$url,
      type: "POST",
      async: false
     }).responseText;
     
  $html = $html.split("#|");
  jQuery('#content').html($html[0]);
  if($html[1] != '') jQuery('title', jQuery('head')).text($html[1]+' | '+$title_base);
  if($html[2] != '') jQuery('meta[name=description]', jQuery('head')).attr('content', $html[2]);
  if($html[3] != '') jQuery('meta[name=keywords]', jQuery('head')).attr('content', $html[3]);
  window.location.hash = $url;
  
  checkUri();
  jQuery('#pagePreloader').hide();
  jQuery('#content').css('opacity', 1);
  if(window.location.hash.indexOf('video') != -1) playVideo(0);
  else if(mp3PlayStatus == !mp3PlayStatus_o) playVideo(mp3PlayStatus_o); 

}


function playVideo($autoPlay){
  
  var so = '<!--[if !IE]> --> '+
           '<object type="application/x-shockwave-flash" data="mp3player.swf" id="player" '+
           'width="155" height="20"> '+
           '<param name="loop" value="true" />'+
           '<param name="wmode" value="transparent" />'+                   
           '<!-- <![endif]--> '+
           '<!--[if IE]> '+
           '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
           'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" '+
           'width="155" height="20">'+
           '<param name="movie" value="mp3player.swf" />'+
           '<!--><!--dgx-->'+
           '<param name="flashvars" value="autoplay='+$autoPlay+'&eqcolor1=264BC6&eqcolor2=E1ECF7&txtcolor=000000" />'+
           '<param name="menu" value="false" />'+
           '<param name="swliveconnect" value="true" />'+
           '<param name="allowScriptAccess" value="always" />'+ 
           '<param name="bgcolor" value="#FFFFFF">'+  
           '</object>'+
           '<!-- <![endif]-->';
  jQuery('#mp3player').html(so);
  mp3PlayStatus = $autoPlay;
}

function GoogleAnaliticsAnchorTracking(){
  var pageTracker = _gat._getTracker('UA-17524956-1');
  pageTracker._trackPageview(window.location.hash);

}


var mp3PlayStatus_o = mp3PlayStatus = 0;
var $windowhash = '';
jQuery(function(){ 
  if(!$ie)checkUri(); playVideo(mp3PlayStatus_o);
  if(jQuery('#pagePreloader').length != 1){
    //jQuery('body').append('<div id="pagePreloader" style="position:absolute;left:0;top:0;padding:2px;color:white;background:#D53FAA;display:none">betöltés ...<\/div>');
  }
  if(!$ie){
    $hash = window.location.hash;
    $hash = $hash.replace("#", '');
    $windowhash = $hash;
    if($hash != '') loadContent($hash);
  }
  if($ie7){
    jQuery('#drop_shadow').css('left', 140);
    //jQuery('#scroll_panel').css('left', -1024);
  }
  
});

jQuery(window).hashchange( function(){
  $uri = window.location.hash.replace("#", '');
  $windowhash = $uri;
  loadContent($uri);
  initTooltip();
  GoogleAnaliticsAnchorTracking();
});
