/***********************************************************************

Author:     Arno Hoogma
URL:        http://www.4rn0.nl

***********************************************************************/


if (typeof window.jQuery != 'undefined') {
	
	/**
	 * sIFR
	 */
	
	var baruta = { src: 'assets/swf/baruta-black.swf' };
	sIFR.activate(baruta);
	
	sIFR.replace(baruta, {
		selector: 'div#content h2, div#content h3',
		transparent: true,
		fitExactly: true,
		css: [
			'.sIFR-root { color: #4c4c4c; }', 
			'a { color: #4c4c4c; text-decoration: none; }', 
			'a:hover { color: #4c4c4c; text-decoration: underline; }'
		]
	});
	
	
	/**
	 * Shadowbox
	 */
	
	Shadowbox.loadSkin('classic', 'css/shadowbox');
	
	
	$(function()
	{

		initExternalAnchors();
		initShadowBox();
	
	});
	

	/**
	 * External links
	 */
	
	function initExternalAnchors()
	{
		
		$('a[rel=external]').attr('target', '_blank');
		
	}


	/**
	 * Shadowbox
	 */
	
	function initShadowBox()
	{
		
		if ($('ol.portfolio li p.images a').size()) {

			$('ol.portfolio li').each(function(i,n) {
				
				$('p.images a', $(n)).attr('rel', 'shadowbox[' + i + ']');

				$('img', $(n)).css('cursor', 'pointer').click(function() {
					$('p.images a:first', $(n)).trigger('click');
				});
								
			});

			$('ol.portfolio li p.images').hide();
			setupShadowBox();
			
		}
		
	}
	
	function setupShadowBox()
	{
		
		Shadowbox.init({
			animSequence: 	'sync',
			onChange: 		shadowBoxOnChange,
			onFinish: 		shadowBoxOnFinish,
			onClose: 		shadowBoxOnClose
		});
		
	}

	function shadowBoxOnChange()
	{
		
		$('div#shadowbox_title_inner').hide();
		
	}

	function shadowBoxOnFinish()
	{
		
		if (sIFR.replacements['div#shadowbox_title_inner']) {
			$('div#shadowbox_title_inner').removeClass('sIFR-replaced');
			sIFR.replacements['div#shadowbox_title_inner'][0].remove();
		}
		
		$('div#shadowbox_title_inner').fadeIn(400);
		
		sIFR.replace(baruta, {
			selector: 'div#shadowbox_title_inner',
			forceSingleLine: true,
			transparent: true,
			css: [
				'.sIFR-root { color: #ffffff; }'
			]
		});
		
	}
	
	function shadowBoxOnClose()
	{
		
		if (sIFR.replacements['div#shadowbox_title_inner']) {
			$('div#shadowbox_title_inner').removeClass('sIFR-replaced').empty();
			sIFR.replacements['div#shadowbox_title_inner'][0].remove();
		}
		
	}
	
}