
$(document).ready( function () {

/**
* NMA hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
  var Skin = new InitSkin();

  /* do some skin-specific DOM-manipulations: */
  Skin.manipulateTheDOM();
  
   /* insert countdown */
  Skin.flashCounterInit();

  /* put your additional method-calls here: */
  
  Skin.changeTheBackground();
  
  
  /* Skin.showTheArtists(); */
  
  Skin.greatestQuotes();
  
  Skin.stationIDs();

});


/**
 * the skin's own js-class
 * use at will
 */
InitSkin = Class.create();

InitSkin.prototype = {

  initialize: function(){

    this.wasInitialized = true;
	this.name = "New Music Award 2010";
	this.shortName = "nma2010";

  },
  
  flashCounterInit: function(){
	this.flashvars = {};
	this.flashvars.xmlURL="/flash/countdown/nma_conf.xml";
	this.params = {};
	this.params.salign = "TL";
	this.params.quality = "best";
	this.params.allowFullScreen = "true";
	this.params.bgColor="#E7501E";
	this.params.wMode="opaque";
	this.attributes = {};
	swfobject.embedSWF("/flash/countdown/counter.swf", "nma_sks_cnt_tim", "196", "36", "9", false, this.flashvars, this.params, this.attributes);
  },

  /**
   * This method should be used to ...
   * 1) put content in places 
   * 2) remove content from places
   * 3) modify existing content
   * only if it proves too difficult to 
   * accomplish manipulation by backend-means
   */
   
   greatestQuotes: function(){
   
   numberOfQuotes=5;
	randomQuote = Math.round(Math.random()*(numberOfQuotes-1))+1;
   
   $(document).ready(function()
	{
	  $.ajax({
	    type: "GET",
	    url: "/nma2010/quotes.xml",
	    dataType: "xml",
	    success: parseXml
	  });
	});
	
	function parseXml(xml)
{
$(xml).find("quote").each(function()
{
	if ($(this).find("id").text() == randomQuote) {
  $("#greatestquotes").append("<div class=\"quote\">\"" + $(this).find("wisdom").text() + "\"</div>");
  $("#greatestquotes").append("<div class=\"genius\">" + $(this).find("genius").text() + "</div>");
  }
});
   }
   },
   
   changeTheBackground: function(){
   if($("#article").length > 0) {
  		/* remove top bar, add smaller top bar, remove background for main wrapper */
  		$("#bg_main_top").hide(0);
  		$("#bg_article_top").show(0);
  		$("#wrapperContent").css({"background": "transparent url(/img/skins/nma2010/bg_article_body.png) bottom left no-repeat"});
  		$("div.teaserContent").css({"background": "#5E5E5E"});
	}
   },
   
   showTheArtists: function(){
   
	bgImageTotal=16;
	randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1;
 
	imgPath=('/img/skins/nma2010/skyscraper_'+randomNumber+'.jpg');
 
	$('#nma_sks_cnt_img').css('background-image', ('url("'+imgPath+'")'));
	
	/*$("#radiostations ul").mouseenter(function () {
		$("#radiostations ul li").animate({opacity: "0.4"}, 800 );
		$("#radiostations ul li").mouseenter(function () {
			$(this).animate({opacity: "1"}, 500 );
		}).mouseleave(function () {
			$(this).animate({opacity: "0.4"}, 500 );
		});
	}).mouseleave(function () {
		$("#radiostations ul li").animate({opacity: "1"}, 800 );
	});*/
	},
	
	stationIDs: function(){
	
	(function($){$.fn.nmaHoverIntent=function(f,g){var cfg={sensitivity:7,interval:20,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
	
	
		// Wenn IE
		if ( $.browser.msie ) {
  			$("#radiostations ul li.station").hoverIntent(function() {
		$(".stationsOverlay", this).css({display: "block"});
		$(this).addClass("active");
		$("#radiostations ul li.station").not(".active").addClass("ie8");
				
		}, function() {
			$(".stationsOverlay", this).css({display: "none"});
			$(this).removeClass("active");
			$("#radiostations ul li.station").not(".active").removeClass("ie8");
		});
  			
			}
		else {
		// Alle anderen funktionieren auch so!
		$("#radiostations ul li.station").hoverIntent(function() {
		$(".stationsOverlay", this).animate({opacity: "1", top: "0"}, 300);
		$(this).addClass("active");
		$("#radiostations ul li.station").not(".active").animate({opacity: "0.4"}, 300);
				
		}, function() {
			$(".stationsOverlay", this).animate({opacity: "0", top: "8px"}, 300);
			$(this).removeClass("active");
			$("#radiostations ul li.station").animate({opacity: "1"}, 300);
		});
	}
	
	// click auf element -> soundkarte
	$("a.streamLinkHead").click(function() {
					var untrimmedID = this.id;
					takeover = new Object();
					takeover = untrimmedID.replace(/link_/i, "");
					var nwl = (screen.width-336)/2;
  					var nwh = (screen.height-294)/2;
  					popUp=window.open('/nma2010/soundkarte.html', 'nma2010oneclick', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=294,height=391,left='+nwl+',top='+nwh+'');
					return false; }
					);
 
},
   
  
  manipulateTheDOM: function(){  

    /* put your DOM-manipulating code here: */
    
	if ($("a.newmusicaward").length > 0) {
		$("a.newmusicaward").empty().text("HOME");
		}
		
	if ( $.browser.msie && $.browser.version < 7.0 ) {
		$("#ie6_box").css({"display": "block"});
	}

  }
  
  /* put your additional - comma-separated - methods here: */
  
};
