var Site = {
  Config: {
	theme_url: '/wp-content/themes/vpro-radio6-4.0'
  },

  Common: {
    init: function(e) {
      $('body').addClass('js');
    },

    /* Change links to open popups, show players etc. */
    linkbehaviour: function() {
	  // make all links with rel=player open the Radio6 player
      $('a[rel="player"]').click(function(){
        window.open(this.href, 'player', 'width=786,height=436');
        return false;
      });

	  // make all links with rel=luisterpaal open the Luisterpaal player
	  $('a[rel="luisterpaal"]').click(function(){
		window.open(this.href, 'luisterpaal', 'width=588,height=707');
		return false;
	  });
	
	  // make all links with rel=gemist open the NEBO player
	  $('a[rel="gemist"]').click(function(){
		window.open(this.href, 'gemist', 'width=1024,height=768');
		return false;
	  });
	
	  // make all links with title=The Beat Player open The Beat Player
	  $('a[title="The Beat Player"]').click(function(){
		window.open(this.href, 'the beat player', 'width=328, height=510, scrollbar=no');
		return false;
	  });
	
	  // make all links with rel=external open in a new window
	  $('a[rel="external"]').attr('target', '_blank');
	
	  // replace all links to mp3 files with a flash player
	  $("a[href$='.mp3']").each(function(){
		var href = $(this).attr('href');
		var player = '<div class="player"><object type="application/x-shockwave-flash" data="'+Site.Config.theme_url+'/flash/player_mp3_maxi.swf" width="200" height="20"> \
		     <param name="movie" value="'+Site.Config.theme_url+'/flash/player_mp3_maxi.swf" /> \
		     <param name="FlashVars" value="mp3='+href+'" /> \
		</object><p>'+$(this).html()+'</p></div>';
		$(this).replaceWith(player);
	  });
	
	  // replace all links to flv files with a flash player
	  $("a[href$='.flv']").each(function(){
		var href = $(this).attr('href');
		var player = '<div class="player"><object type="application/x-shockwave-flash" data="'+Site.Config.theme_url+'/flash/player.swf" width="470" height="320"> \
			<param name="movie" value="'+Site.Config.theme_url+'/flash/player.swf" /> \
			<param name="allowfullscreen" value="true" /> \
			<param name="allowscriptaccess" value="always" /> \
			<param name="wmode" value="transparent" /> \
			<param name="FlashVars" value="file='+href+'" /> \
		</object><p>'+$(this).html()+'</p></div>';
		$(this).replaceWith(player);
      });
	
    },

    /* Cufon initialization */
    cufonize: function(e) {
      if (typeof Cufon != 'undefined') {
        Cufon.replace('#content .box h2, #content .featured h2, #content .cufon, #content-head h1, #content-head h2, #content ul.blogmenu li h3');
      };
    },
    /* Label propagator */
    accessibleInputValues: function(e) {
      labeltxt = $(e).prev().html();
      if ($(e).val() == '') $(e).val(labeltxt);
      $(e)
        .focusin(function() {
          if ($(this).val() == labeltxt) $(e).val('');
        }).focusout(function() {
          if ($(e).val() == '') $(e).val(labeltxt);
        });
      },
    /* Accordion */
    accordion: function(container,head,panel) {
      head = 'ul.accordion > li > .head';
      panel = 'ul.accordion > li > .content';
      $(head).click(function() {
        if ($(this).parent().hasClass('active')) {
			// item is already open; by clicking again close it
			$(this).parent().removeClass('active').children(".content").first().animate({
	            height: ["hide", "linear"],
	            opacity: ["0", "swing"]
			});
        }
        else {
		// item is closed, so open it and display with an animation.
          currentpanel = $(this).next();
          activepanel = $(this).parent().siblings('.active');

          // when the Luister live panel is opened, reload its contents via ajax.
          if(($(this).parent().attr('id')) == 'acc-luister') {
	          $.get(Site.Config.theme_url + "/includes/_now_and_upcoming.php", function(data){
		        currentpanel.html(data);
	          });	
          };

          activepanel.removeClass('active').children('.content').first().animate({
            height: ["hide", "linear"],
            opacity: ["0", "swing"]
          });

          $(this).parent().addClass('active');
          currentpanel.animate({
            height: ["show", "swing"],
            opacity: ["1", "linear"]
          });
        }
      })
    },
    /* Collapsible boxes */
    collapsible: function(e) {
      $('.collapsible .head-closed').next().hide();
      $('.collapsible .head').click(function() {
        $(this).next().toggle();
        $(this).toggleClass("head-closed head-open");
      })
    }
  }
};

$(document).ready(function() {
  Site.Common.init();
  Site.Common.accessibleInputValues($('#search input.text'));
  Site.Common.accordion();
  Site.Common.cufonize();
  Site.Common.collapsible();
  Site.Common.linkbehaviour();
});

function sitestat(ns_l) {
	ns_l+="&ns__t="+new Date().getTime();
	ns_pixelUrl=ns_l;
	ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf("/")==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf("/"),0):ns_0;

	if(ns_0.length>0) ns_l+="&ns_referrer="+escape(ns_0);
  
	if(document.images) {
		ns_1=new Image();
		ns_1.src=ns_l;
	} else {
		document.write("<img src="+ns_l+" width=1 height=1>");
	}
}