
/**
 * Add the son of suckerfish menu to all selected elements
 *
 * jQuery version of this:
 *
 * //  son of suckerfish menu
 * sfHover = function() {
 *   var sfEls = document.getElementById("main-nav").getElementsByTagName("LI");
 *   for (var i=0; i<sfEls.length; i++) {
 *     sfEls[i].onmouseover=function() {
 *       this.className+=" sfhover";
 *     }
 *     sfEls[i].onmouseout=function() {
 *       this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
 *     }
 *   }
 * }
 * if (window.attachEvent) window.attachEvent("onload", sfHover);
 */
jQuery.fn.addSonOfSuckerfish = function() {
	return this.each(function() {
		// check for ie
		if (jQuery.browser.msie) {
			jQuery('> li', this).hover(
				function() { jQuery(this).addClass('sfhover'); },
				function() { jQuery(this).removeClass('sfhover'); }
			);
		}

		jQuery('> li', this).hover(
			function() { jQuery('a:first', this).addClass('sflinkhover'); },
			function() { jQuery('a:first', this).removeClass('sflinkhover'); }
		);
	});
};


/**
 * Render a video with the given media id (from the mediatool) using
 * SWFObject
 *
 * @param   string          media_url
 * @param   string          target
 * @param   int             width
 * @param   int             height
 */
function showVideo(media_url, target, width, height)
{
	displayVideo(media_url, target, width, height);
}

function displayVideo(media_url, target, width, height)
{
	var s1;

	s1 = new SWFObject('http://st.ilsemedia.nl/sanoma/flvplayer_sanoma.swf' , "single", width , height, "7");
	s1.addParam("allowfullscreen","false");
	s1.addVariable("width", width);
	s1.addVariable("height", height);
	s1.addVariable("file", media_url + '.flv');
	s1.addVariable("image", media_url + '_p.jpg');
	s1.addVariable("frontcolor", "0xffffff");
	s1.addVariable("backcolor", "0xffffff");
	s1.addVariable("lightcolor", "0xffffff");
	s1.addVariable("usefullscreen", "false");
	s1.addVariable("showdigits", "false");
	s1.addVariable("showvolume", "false");
	s1.addVariable("autostart", "false");
	s1.addParam('wmode', 'transparent');
	s1.write(target);
}


function initMenuDots() {
	var active_item, active_item_parent, dot;

	active_item = jQuery('#menu > li > a.selected');
	if (!active_item.length) return;

	active_item_parent = active_item.parents('li').eq(0);

	dot = jQuery('<div class="active-dot"></div>');
	jQuery('#dots').append(dot);

	// Position blue dot based on selected on link, otherwise fall back to approximate location
	switch (active_item.text()) {
		case 'Home':
			left = 12;
			break;
		case 'Onze merken':
			left = 83;
			break;
		case 'Over ilse media':
			left = 180;
			break;
		case 'Adverteren':
			left = 300;
			break;
		case 'Werken bij':
			left = 396;
			break;
		case 'Nieuws':
			left = 491;
			break;
		default:
			left = (active_item_parent.position().left + active_item.position().left + parseInt(active_item.css('padding-left')) + 1);
	}
	dot.css('left', left + 'px');
}

