$(function() {

	var mainMenuSubmenus = $('.secondary-menu li ul');

	Shadowbox.init();
	
	$('.secondary-menu > li').mouseenter(function() {
		var subMenu = $(this).children('ul');
		
		mainMenuSubmenus.hide();
		
		if (subMenu.size() == 0)
			return false;
			
		subMenu.show();
	});
	
	mainMenuSubmenus.mouseleave(function() {
		mainMenuSubmenus.hide();
	});
	
	Cufon.replace('.cufon, h1:not(.raw), .highlight span');
	
	$(".header-search-field label").inFieldLabels();
	
	$('a.video').click(function(e) {
	
		e.preventDefault();
	
		var video = $(this).attr('href');
		var title = $(this).attr('title');
		var content = videoContent(video);
		
		Shadowbox.open({
			player: 'html',
			content: content,
			title: title,
			height: 422,
			width: 750,
			onFinish: function() { setupVideoPlayer(video); }
		});
	
	});
	
	$('.mouseover-image').each(function() {
	
		var imgOver = new Image();
		var imgOverSrc = $(this).data('mouseover');
		var imgOutSrc = $(this).data('mouseout');
		var fadeTime = $(this).data('fade');
		
		imgOver.src = imgOverSrc;
		
		if (!fadeTime) {
		
			$(this).hover(function() {
				$(this).attr('src', imgOverSrc);
			}, function() {
				$(this).attr('src', imgOutSrc);
			});
			
		} else {
			
			$(this).mouseover(function() {
			
				var parent = $(this).parent();
				var pos = $(this).offset();
				var fadeImg = $('<img />').appendTo('body')
										  .attr('src', imgOverSrc)
										  .hide()
										  .css({ 'position': 'absolute', 'top': pos.top, 'left': pos.left })
										  .fadeIn(fadeTime)
										  .mouseout(function() { $(this).fadeOut(fadeTime, function() { $(this).remove(); }); })
										  .click(function() { if (parent.is('a')) window.location = parent.attr('href'); });
			
			});		 
		
		}
	
	});

});

function videoContent(url) {
    
    var html = '';
    
    html += '<object width="750" height="422"';
  	html += 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
  	html += 'codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
  	html += '<param name="src" value="'+url+'">';
  	html += '<param name="controller" value="true">';
  	html += '<param name="autoplay" value="true">';
  	html += '<param name="scale" value="aspect">';
  	html += '<embed src="'+url+'" width="750" height="422"';  
    html += 'autoplay="true" controller="true"'; 
    html += 'pluginspage="http://www.apple.com/quicktime/download/" scale="aspect">';
  	html += '</embed>';
	html += '</object>';
    
    return html;

    //var oggUrl = url.replace('.mp4', '.ogg');
    //var webmUrl = url.replace('.mp4', '.webm'); 
    
    //html += '<video height="422" width="750" autoplay controls>';
    
    //html += '<source src="'+url+'" type="video/mp4" />';
    //html += '<source src="'+oggUrl+'" type="video/ogg" />';
    //html += '<source src="'+webmUrl+'" type="video/webm" />';
    
    //html += '<object id="flowplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="750" height="422">';
    //html += '<param name="movie" value="flash/flowplayer-3.2.7.swf" />';
    //html += "<param name=\"flashvars\" value='config={\"clip\":\""+url+"\"}' />";
    //html += '<embed type="application/x-shockwave-flash" width="750" height="422" src="flash/flowplayer-3.2.7.swf"';
    //html += " flashvars='config={\"clip\":\""+url+"\"}'/>";
    //html += '</object>';
    
    //html += '</video>';
    
}

function reinitFlexCroll() {

	$('.vscrollerbase').animate({ 'left': '-=3px' }, 0);

}

window.onfleXcrollRun=function() { 

	reinitFlexCroll();

}

var addthis_config =
{
   'ui_language' : 'sv',
   'ui_header_color' : '#000'
}
