var DEXIA=(!DEXIA)?{}:DEXIA;
DEXIA.slideshow=(function(){
/**
* Switches slideshow component specific markup required
*
* @author		mga
* @name			DEXIA.slideshow
* @usage		DEXIA.slideshow.init();
* @params		id: string: css selector of the container of the slideshow
* @params		t: integer: delay between slide switch
* @example		DEXIA.slideshow.init("#SlideShow",3500);
*/
	var currentSlide=0,init,toggle,autostart,target=0;
	init=function(id,t){
		this.autostartTimer=t;
		this.slideshowId=id;
		this.asI=null;//autostartInterval
		//instanication
		this.overlayers=(typeof(this.overlayers)!="undefined")?this.overlayer:$(this.slideshowId+" div").not(this.slideshowId+" div div");
		//hiding all divs
		$(this.overlayers).each(function(n){if (n!=currentSlide){$(this).hide();}});
		//binding mouseover Events
		this.anchors=$(this.slideshowId+" ul li");
		$(this.anchors).each(function(n){
			var i=n;
			$(this).bind("mouseover",function(e){
				DEXIA.slideshow.toggle(e,i);
			});
			if (i==currentSlide){DEXIA.slideshow.toggle({currentTarget:$(this)},i);}
		});
		//autofiring the rotation
		this.autostart();
		$(this.slideshowId).bind("mouseover",function(){clearTimeout(DEXIA.slideshow.asI);DEXIA.slideshow.asI=null;return false;});
		//adding id on the last element in order to remove the background image (which is the bottom line...)
		$(this.slideshowId).find("li:last-child").attr("id","last_elm");
		$("body").bind("mouseover",function(){if (DEXIA.slideshow.asI===null){DEXIA.slideshow.autostart();}return false;});
	};
	autostart=function(){
		var target=(currentSlide>=($(this.anchors).length-1))?0:currentSlide+1;
		var elm={currentTarget:$(this.slideshowId+" li:nth-child("+(target+1)+")")}
		this.asI=setTimeout(function(){DEXIA.slideshow.toggle(elm,target);DEXIA.slideshow.autostart()},this.autostartTimer);
	}
	toggle=function(e,i){
		var src=(typeof(e.srcElement)!="undefined")?e.srcElement:e.currentTarget;
		$($("#SlideShow ul li").get(currentSlide)).removeClass("active");
		$(this.overlayers).each(function(){
			$(this).hide();
		});
		$($("#SlideShow ul li").get(i)).addClass("active");
		if($("p",this.overlayers[i]).html()!=""){
			$("p",this.overlayers[i]).css({top:$(src).offset().top-279});
			/*@cc_on //fixing IE6 png bg
				if(parseInt($.browser.version)<=6){
					$("img",this.overlayers[i]).css({top:$(src).offset().top-279});
				}
			@*/
		}else{
			$("p",this.overlayers[i]).css({top:$(src).offset().top-9999});
			$("img.png",this.overlayers[i]).css({top:$(src).offset().top-9999});
		}
		
		
		$(this.overlayers[i]).fadeIn(0);
		currentSlide=i;
	};
	return {
		init:init,
		toggle:toggle,
		autostart:autostart
	};
})();

