// Scenes
jQuery.noConflict();

// Dom ready
jQuery(document).ready(function($){								
	var SCENES = {
		steps: [],
		triggerClass: "sceneJs", // class to trigger the scenes
		stepSuffix: "step", // step DIV ID
		overLayClass: "overlay",
		overLayOpacity: 50, // 50% for IE
		stepClass: "scene",
		stepCurrentClass : "scene_current",
		stepCloseClass: "scene_action",
		speed: 800, // Speed of animation
		
		init: function(selector) {
			$(selector).each(function() {
				$(this).click(function() {
					SCENES.start();
					return false;
				});				
			});
		},
		
		start: function() {
			var $overlay = $("."+this.overLayClass);
			if ($.browser.msie) {
				$overlay.css("display","block").css("width", $(window).width()+"px").css("height", $(document).height()+"px").css("filter","alpha(opacity="+this.overLayOpacity+")");	
			}
			$overlay.fadeIn("slow");
			
			// Build scenes
			SCENES.steps = [];
			$("."+this.stepClass).each(function() {
				try {
					var sequence = $(this).attr("id").split("_")[1];
					if (!isNaN(sequence)) {
						SCENES.steps.push(sequence);
					}
				} catch(e) {}
			});
			SCENES.steps.sort();			
			for (var i=0;i<SCENES.steps.length;i++) {
				SCENES.steps[i]	= $(this.buildId(i+1));
			}
			// Just roll out
			SCENES.show(1);
		},
		
		show: function(step) {
			var toScroll = true;
			// hide previous steps
			SCENES.hide();
			
			var $step = $(this.buildId(step));

			// set link actions
			$step.find("a").unbind("click").click(function() {
				SCENES.show(step+1);
				return false;							   
			});
			
			// set close actions
			$step.find("."+this.stepCloseClass).unbind("click").click(function() {
				$("."+SCENES.overLayClass).fadeOut();
				SCENES.hide();
				return false;
			});

			if ($step.length > 0) {
				$step.addClass(this.stepCurrentClass).css("zIndex",this.getTopZIndex());
				if (toScroll) {
					var top = parseInt($step.css("top"),10)-$step.outerHeight();
					$.scrollTo({top: top, left: $step.css("left")}, this.speed);
				}
			} else {
				var $lastLink = $(this.buildId(step-1)).find("a");
				$lastLink.unbind("click");
				window.location.href = $lastLink.attr("href");
			}
		},
		
		hide: function() {
			$("."+this.stepClass).each(function() {
				$(this).removeClass(SCENES.stepCurrentClass);							   
			});
		},
		
		buildId: function(step) {
			return "#"+SCENES.stepSuffix+"_"+step;	
		},
		
		getTopZIndex: function() {
			var allElems = document.getElementsByTagName ? document.getElementsByTagName("*"): document.all; // or test for that too
			var maxZIndex = 9999999;
			for(var i=0;i<allElems.length;i++) {
				var elem = allElems[i];
				var cStyle = null;
				if (elem.currentStyle) {
					cStyle = elem.currentStyle;
				} else if (document.defaultView && document.defaultView.getComputedStyle) {
					cStyle = document.defaultView.getComputedStyle(elem,"");
				}
				var sNum;
				if (cStyle) {
					sNum = Number(cStyle.zIndex);
				} else {
					sNum = Number(elem.style.zIndex);
				}
				if (!isNaN(sNum)) {
					maxZIndex = Math.max(maxZIndex,sNum);
				}
			}
			return maxZIndex;	
		}
		
	};
	
	SCENES.init("."+SCENES.triggerClass);
});


function jsFunctionclose()
{
 /*$("."+SCENES.overLayClass).fadeOut();
				SCENES.hide();
				return false;*/
				
	alert("testbouton");
}
