/**
 * Momkai 
 * Copyright 2010 Momkai (www.momkai.com)
 * 
 * @author Theun de Bruijn (theun@momkai.com)
 * 
 * @version 1.0
 */
 

/** _______________________________________________________________________________________
* ___              ________________________________________________________________________
* ___|  on ready  |________________________________________________________________________
* _________________________________________________________________________________________
*/

$(document).ready(function()
{
	/* 
	 * catch undefined console
	 */
	
	try { console.log('console ready'); } catch(e) { console = { log: function() {} } }
	console.log("ready() called");

	/*
        SU11 specifics
    */

    //$("#nike_content_homepage").css("position", "absolute");
    /*
    $("#nike_flash_rectangle").append('<div id="su11" style="position: absolute; margin-left: 1px;"></div>');
    $("#nike_flash_rectangle").append('<div id="nike" style="position: absolute;"></div>');

    $("#su11").prepend('<div id="facebookvote" style="position: absolute; top:278px; left: 29px; width: 83px; height: 22px; background-color: #273f7d; z-index: 10; cursor: pointer; display: none; opacity: 0.00001; filter: alpha(opacity = 0.00001);"></div>');
    $("#su11").prepend('<div id="twittervote" style="position: absolute; top:278px; left: 141px; width: 83px; height: 22px; background-color: #24bbff; z-index: 10; cursor: pointer; display: none; opacity: 0.00001; filter: alpha(opacity = 0.00001);"></div>');
    $("#su11").prepend('<div id="hyvesvote" style="position: absolute; top:278px; left: 253px; width: 83px; height: 22px; background-color: #f79832; z-index: 10; cursor: pointer; display: none; opacity: 0.00001; filter: alpha(opacity = 0.00001);"></div>');
		$("#su11").prepend('<div id="facebooklink" style="position: absolute; top:276px; left: 28px; width: 309px; height: 44px; background-color: #f79832; z-index: 10; cursor: pointer; display: block; opacity:0.00001; filter: alpha(opacity = 0.00001);"></div>');
	
    $("#su11").append('<div id="nike_flash_rectangle_su11" style="position: absolute; z-index: 1;"></div>');
    $("#nike").append('<div id="nike_flash_rectangle_smartad" style="position: absolute; z-index: 1;"></div>');
    */
    //addLikeButton("-153","346");

    //bindSu11Events();

    embedFlash("SmartAd", "nike_flash_rectangle", 368, 395, "window", "nike_flash_rectangle");

	// Check first for the tags in the text
	//searchTags();	
	/*
	// on nike page show both
	if(typeof(bNikepage) == "boolean") {
		console.log("ok");
		$("#nike_flash_rectangle").css("height", "800px");
		
		// separate elements
		$("#nike").css("margin-top", "400px");

		// embeds
		embedFlash("Nike_SU11_VotingBanner", "nike_flash_rectangle_su11", 366, 395, "transparent", "nike_flash_rectangle_su11");
		embedFlash("SmartAd", "nike_flash_rectangle_smartad", 368, 395, "window", "nike_flash_rectangle_smartad");
		
	} else {
	
		// else only show the votingbanner
		embedFlash("Nike_SU11_VotingBanner", "nike_flash_rectangle_su11", 366, 395, "transparent", "nike_flash_rectangle_su11");
	}
    */
	/*
	 * Solo SmartAd embed
	 */
/*
      // embeds
    embedFlash("SmartAd", "nike_flash_rectangle_smartad", 368, 395, "window", "nike_flash_rectangle_smartad");
*/

	/*
	 * Solo votingbanner embed
	 */
/*
      // embeds
      embedFlash("Nike_SU11_VotingBanner", "nike_flash_rectangle_su11", 366, 395, "transparent", "nike_flash_rectangle_su11");
*/

});


/** _______________________________________________________________________________________
* ___                              _______________________________________________________________
* ___|  Rectangle specific functions  |_______________________________________________________________
* _________________________________________________________________________________________
*/

/*
 * Function that returns the title and <p> data
 * of the news item. It can be called from the
 * Flash rectangle banner.
 * 
 */

function getItemData() {
	
	var sTitle 	= $("#content .title > h2").text();
	var sCopy	= $("#content .about-team p").text();	

	oData = new Object();
	
	oData = {
		
		"title" : sTitle,
		"copy"	: sCopy
	
	};
	
	return oData;
	
}


/** _______________________________________________________________________________________
* ___              					 ______________________________________________________
* ___|  generic swfobject function  |______________________________________________________
* _________________________________________________________________________________________
*/

/*
 * Generic SWF Embed function
 */

function embedFlash(fileName, replaceDivId, nWidth, nHeight, windowMode, htmlClassName)
{
	
	var flashvars 	= {
		//currentplayer : activePlayer
	}

	var params		= 
	{ 
		scale	: "noscale", 
		menu	: "false", 
		wmode	: windowMode,
		allowfullscreen		: "true" 
	}; 
	
	var attributes	=
	{
		'class'	: htmlClassName
	};
 
	
	swfobject.embedSWF("momkai/core/bin/" + fileName + ".swf", replaceDivId, nWidth, nHeight, "9", "false", flashvars, params, attributes);	
};


/** _______________________________________________________________________________________
* ___              					  _____________________________________________________
* ___|  SU11 Superfly functionality  |_____________________________________________________
* _________________________________________________________________________________________
*/
/*
// set active player (based on text content)
var activePlayer = "0";
*/
function getFlashMovie(flashId) {
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		return window[flashId];
	} else {
		return document[flashId];
	}
};
/*
function bindSu11Events() {

	$("#facebookvote").bind("click", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("voteSuccess");
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("click_facebookvote");
		window.open("http://nikefootball.momkai.com/core/php/app.superfly/facebook_vote.php?player_id="+activePlayer+"", "popup", "width=960,height=500");
	}).bind("mouseenter", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollover_facebookvote");
	}).bind("mouseleave", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollout_facebookvote");
	});

	$("#twittervote").bind("click", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("voteSuccess");
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("click_twittervote");
		window.open("http://nikefootball.momkai.com/core/php/app.superfly/facebook_vote.php?player_id="+activePlayer+"", "popup", "width=960,height=500");
	}).bind("mouseenter", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollover_twittervote");
	}).bind("mouseleave", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollout_twittervote");
	});

	$("#hyvesvote").bind("click", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("voteSuccess");
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("click_hyvesvote");
		window.open("http://nikefootball.momkai.com/core/php/app.superfly/facebook_vote.php?player_id="+activePlayer+"", "popup", "width=960,height=500");
	}).bind("mouseenter", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollover_hyvesvote");
	}).bind("mouseleave", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollout_hyvesvote");
	});
	
	$("#facebooklink").bind("click", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("click_facebooklink");
		window.location = "http://www.facebook.com/nikefootballNL?sk=wall";
	}).bind("mouseenter", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollover_facebooklink");
	}).bind("mouseleave", function() {
		getFlashMovie("nike_flash_rectangle_su11").reportEvent("rollout_facebooklink");
	});		
}


function showOverlay(elemId) {
	$(elemId).css("display", "block");
	console.log("showOverlay called" + elemId);
}

function hideOverlay(elemId) {
	$(elemId).css("display", "none");
	console.log("hideOverlay called" + elemId);
}

function addLikeButton(nMarginLeft, nMarginTop) {
	console.log("hideOverlay called");
	$('#su11').append('<iframe id="facebooklike" style="position: absolute; top: 0%; left: 50%; max-width: 150px; max-height: 30px; margin-top: '+ nMarginTop +'px; margin-left: '+ nMarginLeft +'px; display: none; z-index: 10;" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fhome.php%23%21%2Fpages%2FNike-Football-Nederland%2F116614965038945&amp;layout=button_count&amp;show_faces=false&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>');
}
*/
/*
	Active player section
*/

// counter array
/*
_aTags =
[
	{
		tags:[ 'Chadli', 'Twente' ],
		count:0
	},
	{
		tags:[ 'Lens', 'PSV'],
		count:0
	},
	{
		tags:[ 'Eriksen', 'Ajax' ],
		count:0
	}
];

function searchTags()
{
	// get the item text (count the title double)
	sText = getItemData().title + getItemData().title + getItemData().copy;
	
	// loop players
	for (var i = 0; i < _aTags.length; i++)
	{
		
		// tags
		for (var j = 0; j < (_aTags[i]['tags']).length; j++)
		{
			
			// init
			var sTag = _aTags[i]['tags'][j].toLowerCase();					
			var nTagCount = (sText.toLowerCase().split(sTag).length - 1);
			
			// register
			if (nTagCount > 0) _aTags[i]['count'] += nTagCount;
		}
	}
	
	setDefaultPlayer();

}


function setDefaultPlayer() {
	
	if (_aTags[0].count > _aTags[1].count && _aTags[0].count > _aTags[2].count) {
		activePlayer = "1";
	} else if (_aTags[1].count > _aTags[0].count && _aTags[1].count > _aTags[2].count) {
		activePlayer = "2";
	} else if (_aTags[2].count > _aTags[0].count && _aTags[2].count > _aTags[1].count) {
		activePlayer = "3";
	}
}

function setActivePlayer(playerId) {
	activePlayer = playerId;
}	
*/	
