Fx.Height = Fx.Style.extend({initialize: function(el, options){$(el).setStyle('overflow', 'hidden');this.parent(el, 'height', options);},toggle: function(){var style = this.element.getStyle('height').toInt();return (style > 0) ? this.start(style, 0) : this.start(0, this.element.scrollHeight);},show: function(){return this.set(this.element.scrollHeight);}});Fx.Opacity = Fx.Style.extend({initialize: function(el, options){this.now = 1;this.parent(el, 'opacity', options);},toggle: function(){return (this.now > 0) ? this.start(1, 0) : this.start(0, 1);},show: function(){return this.set(1);}});

window.addEvent("load",function(){
	$$(".gk_is_wrapper").each(function(el){
		var elID = el.getProperty("id");
		var wrapper = $(elID);
		var $G = $Gavick[elID];
		var animation_slide_speed = $G['anim_speed'];
		var animation_interval = $G['anim_interval'];
		var autoanimation = $G['autoanim'];
		var animation_slide_type = $G['anim_type'];
		var slides = [];
		var links = [];
		var loadedImages = ($E('.gk_is_preloader', wrapper)) ? false : true;
	
		if($E('.gk_is_preloader', wrapper)){
			var imagesToLoad = [];
			
			$ES('.gk_is_slide',wrapper).each(function(el,i){
				links.push(el.getChildren()[1].getProperty('href'));
				var newImg = new Element('img',{
					"src":el.getChildren()[0].getProperty('href'),
					"alt":el.getProperty('title'),
					"class":el.getProperty('class'),
					"style":el.getProperty('style')
				});
				imagesToLoad.push(newImg);
				newImg.injectAfter(el);
				el.remove();
			});
			
			var timerrr = (function(){
				var process = 0;				
				imagesToLoad.each(function(el,i){
					if(el.complete) process++;
 				});
 				
				if(process == imagesToLoad.length){
					$clear(timerrr);
					loadedImages = process;
					(function(){new Fx.Opacity($E('.gk_is_preloader', wrapper)).start(1,0);}).delay(400);
				}
			}).periodical(200);
		}
		
		var timerrr2 = (function(){
		if(loadedImages){
		$clear(timerrr2);
		// ----------	
		wrapper.getElementsBySelector(".gk_is_slide").each(function(elmt,i){
			slides[i] = elmt;
			if($G['slide_links'] == 1){
				elmt.addEvent("click", function(){window.location = elmt.getProperty('alt');});
				elmt.setStyle("cursor", "pointer");
			}
		});
		
		slides.each(function(el,i){if(i != 0) el.setOpacity(0);});
		
		if($E(".gk_is_prev", wrapper)){
			$E(".gk_is_prev", wrapper).addEvent("click",function(e){
				new Event(e).preventDefault();
				gk_is_anim2(elID,wrapper,slides,animation_slide_speed,(($G['actual_slide'] > 0) ? $G['actual_slide']-1 : slides.length-1),animation_slide_type, $G);
			});

			$E(".gk_is_next", wrapper).addEvent("click",function(e){
				new Event(e).preventDefault();
				gk_is_anim2(elID,wrapper,slides,animation_slide_speed,(($G['actual_slide'] < slides.length-1) ? $G['actual_slide']+1 : 0),animation_slide_type, $G);
			});
		
			$E(".gk_is_play", wrapper).addEvent("click",function(e){
				new Event(e).preventDefault();
				gk_is_anim(wrapper,slides,elID,animation_interval,animation_slide_speed,"right",true,animation_slide_type, $G);
				$E(".gk_is_play", wrapper).setStyle("display","none");
				$E(".gk_is_pause", wrapper).setStyle("display","block");
			});
		
			$E(".gk_is_pause", wrapper).addEvent("click",function(e){
				new Event(e).preventDefault();
				gk_is_pause(elID, $G);
			});
		}
		
		$G['actual_slide'] = 0;
		
		if(autoanimation == 1){
			gk_is_anim(wrapper,slides,elID,animation_interval,animation_slide_speed,"right",true,animation_slide_type, $G);
			if($E(".gk_is_play", wrapper)) $E(".gk_is_play", wrapper).setStyle("display","none");
		}else{
			if($E(".gk_is_pause", wrapper)) $E(".gk_is_pause", wrapper).setStyle("display","none");
		}
		// ----------
		}}).periodical(250);
	});
});

function gk_is_anim(wrapper,slides,elID,ai,ass,direct,play,animation_slide_type, $G){
	var max = slides.length-1;
	
	if(!$G['actual_animation']){
		$G['actual_animation'] = (function(){
			if(direct == "left") var actual_slide2 = ($G['actual_slide'] == 0) ? 0 : $G['actual_slide'];
			if(direct == "right") var actual_slide2 = ($G['actual_slide'] == max) ? max : $G['actual_slide'];
			if(direct == "left") ($G['actual_slide'] == 0) ? $G['actual_slide'] = max : $G['actual_slide'] -= 1;
			if(direct == "right") ($G['actual_slide'] == max) ? $G['actual_slide'] = 0 : $G['actual_slide'] += 1;
			slides[$G['actual_slide']].setStyle("z-index",max+1);
		
			new Fx.Opacity(slides[actual_slide2],{duration: ass}).start(1,0);
			$G['actual_animation_p'] = true;
			new Fx.Opacity(slides[$G['actual_slide']],{duration: ass}).start(0,1);
				
			if(animation_slide_type == 'top') new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.y,0);
			if(animation_slide_type == 'left') new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.x,0);
			if(animation_slide_type == 'bottom') new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.y,0);
			if(animation_slide_type == 'right') new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.x,0);
				
			(function(){slides[$G['actual_slide']].setStyle("z-index",$G['actual_slide']);}).delay(ass);
			(function(){$G['actual_animation_p'] = false;}).delay(ass);
		}).periodical(ass+ai);
		(function(){if(!play) gk_is_pause(elID, $G);}).delay(ass+ai);
	}
}

function gk_is_anim2(elID,wrapper,slides,ass,direct,animation_slide_type, $G){
	var max = slides.length-1;
	
	if(!$G['actual_animation_p'] && direct != $G['actual_slide']){
		var actual_slide2 = $G['actual_slide'];
		$G['actual_slide'] = direct;
		slides[$G['actual_slide']].setStyle("z-index",max+1);
		
		new Fx.Opacity(slides[actual_slide2],{duration: ass}).start(1,0);
		$G['actual_animation_p'] = true;
		new Fx.Opacity(slides[$G['actual_slide']],{duration: ass}).start(0,1);
	
		if(animation_slide_type == 'top') new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.y,0);
		if(animation_slide_type == 'left') new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.x,0);
		if(animation_slide_type == 'bottom') new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.y,0);
		if(animation_slide_type == 'right') new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.x,0);
		
		(function(){slides[$G['actual_slide']].setStyle("z-index",$G['actual_slide']);}).delay(ass);
		(function(){$G['actual_animation_p'] = false;}).delay(ass);
		
		gk_is_pause(elID, $G);
	}
}

function gk_is_pause(elID, $G){
	var wrapper = $(elID);
	$clear($G['actual_animation']);$G['actual_animation'] = false;
	if($E(".gk_is_play", wrapper)){
		$E(".gk_is_play", wrapper).setStyle("display","block");
		$E(".gk_is_pause", wrapper).setStyle("display","none");
	}
}