/* sIFR Replacement */
if(typeof sIFR == "function"){
	sIFR.setup();
	sIFR.replaceElement(
	    "h2, " +
	    "#work-detail h3," + 
	    "#about h3", 
	    named({
	    	sFlashSrc: "http://www.robert-rockmann.de/swf/museo.swf", 
	    	sColor: "#ffffff", 
	    	sCase: "lower", 
	    	sBgColor: "#000000",
	    	sLinkColor: "#ffff00",
	    	sHoverColor: "#ffffff",
	    	sWmode: "transparent"
	    })
	);
}

/* jQuery Stuff */
(function($) {
	$(document).ready(function() {    	
    	init.main();
    	
    	if($('#work')) {
    		init.work();
    	}
	});
	
	var init = {
		main: function() {
			
			var swfAtts = {},
				swfParams = {
					allowscriptaccess: "always",
					bgcolor: "#ffffff",
					wmode: 'transparent'
				}
			;
					
			// Embedding
			var video_url = "http://www.robert-rockmann.de/swf/video-home.swf";
			
			if($('#about').length || $('#contact').length || $('#imprint').length) {
				video_url = "http://www.robert-rockmann.de/swf/video-work.swf";
			}
			
			swfobject.embedSWF(video_url, "swf-holder", "100%", "100%", "8", null, null, swfParams, swfAtts);
		},
		home: function() {
		
		},		
		work: function() {
			switchImpressionImages();
		}	
	}
	
	/* functions */	
	function switchImpressionImages() {
		var impressions = $('ul.impressions'),
			hoverTimer
		;
		
		impressions
			.hover(function() {
				var jElem = $(this),
					currentImpressions = $('li', jElem),
					currentCount = currentImpressions.length,
					nextElemIndex,
					currentIndex
				;
				
				switchImage();
				
				hoverTimer = setInterval(switchImage, 1000);
				
				function switchImage() {
					currentIndex = currentImpressions.index($('.active', jElem));
					
					if (currentIndex+1 < currentCount) {
						nextElemIndex = currentIndex+1;
					} else {
						nextElemIndex = 0;
					}
										
					currentImpressions
						.removeClass('active')
						.filter(':eq('+ nextElemIndex +')')
							.addClass('active')
					;
				}
				
			}, function() {
				// reset to first image				
				clearInterval(hoverTimer);
				
				var jElem = $(this);
				
				$('li', jElem)
					.removeClass('active')
					.filter(':first')
						.addClass('active')
				;
			})
		;
	}
	
	
})(jQuery);
