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;
          });

          // social player (video, twitter)
          $('a[rel="socialplayer"]').click(function(){
            window.open(this.href, "socialplayer", 'resizable=yes,scrollbars=no,width=950,height=644,status=no,menubar=no,toolbar=no,location=no,directories=no');
            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 video files with a flash player
	  $("a[href$='.flv'], a[href$='.mp4']").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="490" height="334"> \
			<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, #content .nivo-caption strong');
      };
      
    },
    /* 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 > div.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');

          $(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");
      })
	},
	/* Carousel Init */
	nivoSliderInit: function(e) {
		if (typeof $.fn.nivoSlider != 'undefined') {
			$('#slider').nivoSlider({
	        effect:'fade', //Specify sets like: 'random,fold,fade,sliceDown'
	        animSpeed:250, //Slide transition speed
	        pauseTime:6000, // miliseconds
	        startSlide:0, //Set starting Slide (0 index)
	        directionNav:false, //Next & Prev
	        controlNav:true, //1,2,3...
	        controlNavThumbs:false, //Use thumbnails for Control Nav
	        keyboardNav:true, //Use left & right arrows
	        pauseOnHover:true, //Stop animation while hovering
	        manualAdvance:false, //Force manual transitions
	        captionOpacity:1, //Universal caption opacity
	        beforeChange: function(){},
	        afterChange: function(){
			// $('.nivo-controlNav a.active-complete').removeClass('active-complete');
			// $('.nivo-controlNav a.active').addClass('active-complete');
			if (typeof Cufon != 'undefined') {
				Cufon.replace('#content .nivo-caption strong');
			};
		}
	    });
      $('.nivo-controlNav a').click(function() {
      	$('#slider').data('nivo:vars').stop = true;
      });
    }
	}
  }
};

$(document).ready(function() {
  Site.Common.init();
  Site.Common.accessibleInputValues($('#search input.text'));
  Site.Common.accordion();
  Site.Common.cufonize();
  Site.Common.nivoSliderInit();
  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>");
	}
}

