
var setUpPage = function(){
	var aL = $('#artworkleft');
	var aR = $('#artworkright');
	var mW = $('#mainwrap');
	var sL = $('#shadowleft');
	var sR = $('#shadowright');
	var mWw = mW.offset().left;
	var mWh = mW.height();
	aL.css('left', mWw - aL.width() );
	aR.css('left', mWw + mW.width() );
	sL.css('left', mWw - sL.width() );
	sR.css('left', mWw + mW.width() );
	sL.css('height', mWh  );
	sR.css('height', mWh );
	
	var vPortWidth = $(window).width();
	if( vPortWidth <= mW.width() ) {
		$('body').css('overflow-x', 'scroll');
	}
	else {
		$('body').css('overflow-x', 'hidden');
	}
}

var setUpSearch = function(){
	
	$('#searchkeyword').bind('focus', function(){
		if( this.value == 'zoeken') {
			this.value = '';
		}
	});

	$('#searchkeyword').bind('blur', function(){
		if( this.value.length == 0) {
			this.value = 'zoeken';
		}
	});
}

var homePlayer = null;

$(document).ready(function() {

$("a").bind("focus",function(){if(this.blur)this.blur();});

	setUpPage();
	$(window).resize(function() {
		setUpPage();
	});
	
	setUpSearch();

	$('#shadowleft').show();
	$('#shadowright').show();
	$('#artworkleft').show();
	$('#artworkright').show();

    homePlayer = $f(
    		"player",
    		"/Plugins/External/Flowplayer/flowplayer-3.1.2.swf",
			{ 
			    	clip:  { 
			    			autoPlay: false, 
			    			autoBuffering: true 
			    		},
			    		onFinish: function(){this.getPlugin("play").hide()},

			    		plugins: {controls: null} 			    	
			}
    ).controls("hulu", {duration: 25}); 

$('#iconSoundMute').bind('click', function(){

	var soundState = WawCookie.readCookie('soundstatus');
	if( soundState == null ) {
		WawCookie.createCookie('soundstatus', 0, '');
	}

	if( $('#iconSoundMute').attr('class') == 'iconSoundMute') {
		$('#iconSoundMute').attr('class', 'iconSound');
		homePlayer.unmute();
		WawCookie.createCookie('soundstatus', 0, '');
	}
	else {
		$('#iconSoundMute').attr('class', 'iconSoundMute');
		homePlayer.mute();
		WawCookie.createCookie('soundstatus', 1, '');
	}
	return false;
});
	
});

var playPortfolioMovie = function(url, shortcode, sitemapid, compName, indx){
	
	return __PLAY_MOVIE(
			url, 
			shortcode, 
			sitemapid, 
			compName, 
			indx, 
			'txt_portfolio_details', 
			'txt_portfolio_details_demo', 
			'txt_portfolio_volledig_demo'
		);
};

var playPortfolioMovieHome = function(url, shortcode, sitemapid, compName, indx){
	
	return __PLAY_MOVIE(
			url, 
			shortcode, 
			sitemapid, 
			compName, 
			indx, 
			'txt_portfolio_details_home', 
			'txt_portfolio_details_home_demo', 
			'txt_portfolio_volledig_home_demo'
		);
};


var getCurrentContent = function (shortcode, sitemapid) {
	
	comName = 'txt_current_content';
	var siteId = '1';
	if( siteId == '2' ) {
		comName = 'txt_current_content_demo';
	}
	
	var success = function ( html ) {
		$('#msectioncontent').html(html);
	};
	var other = { 
		"shortcode" : shortcode,
		"sitemapid" : sitemapid,
		"componentname" : comName
	};
	WawClient.callComponent ( 'content', 'view', 'get_content_by_short_code', success, 'html', other );		
}

var __PLAY_MOVIE = function(url, shortcode, sitemapid, compName, indx, comName1, comName2, comName3){
	
	if(indx == null) indx = 0;

	if( url.length > 0 ) {

		var soundState = WawCookie.readCookie('soundstatus');
		if( soundState == null ) {
			WawCookie.createCookie('soundstatus', 0, '');
			soundState = '0';	
		}
		
		comName = comName1;
		var siteId = '1';
		if( siteId == '2' ) {
			comName = comName2;
			if( compName != null) {
				compName = comName3;
			}
		}
		if( compName != null) {
			comName = compName;
		}

		homePlayer.play(url);

		var success = function ( html ) {
				$('#content').html(html);
		};
	    var other = { 
	    		"shortcode" : shortcode,
			"sitemapid" : sitemapid,
			"index" : indx,
	    		"componentname" : comName
	    };
	    WawClient.callComponent ( 'content', 'view', 'get_content_by_short_code', success, 'html', other );		

	    getCurrentContent(shortcode, sitemapid);
	    
		if( soundState == '0' ){
			$('#iconSoundMute').attr('class', 'iconSound');
			homePlayer.unmute();
		}
		else {
			$('#iconSoundMute').attr('class', 'iconSoundMute');
			homePlayer.mute();
		}
	}
	return false;
};


$(document).ready(function() {
var soundState = WawCookie.readCookie('soundstatus');
if(homePlayer != null ) {
	homePlayer.play();
	if( soundState != null && soundState == '0') {
		homePlayer.unmute();
		$('#iconSoundMute').attr('class', 'iconSound');
	}
	else if(soundState != null && soundState == '1') {
		homePlayer.mute();
		$('#iconSoundMute').attr('class', 'iconSoundMute');
	}
	else {
		homePlayer.unmute();
		$('#iconSoundMute').attr('class', 'iconSound');
	}
}	
});

