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 base_bgcolor = $G['bgcolor'];
		var base_opacity = $G['opacity'];
		var slides = [];
		var contents = [];
		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);
		// ----------	
		if(window.ie){
			if($E(".gk_is_text_bg", wrapper)) $E(".gk_is_text_bg",wrapper).setOpacity(base_opacity.toFloat());
		}
		
		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);});
		
		var ticks_array = [];
		
		if($E('.gk_is_tick_buttons', wrapper)){
			$ES('.tick', wrapper).each(function(el,x){
				ticks_array[x] = el;
				
				el.addEvent("click",function(){
					gk_is_anim2(elID,wrapper,slides,contents,animation_slide_speed,x,animation_slide_type, $G, ticks_array);
				});
			});
			
			ticks_array[0].setProperty("class", (ticks_array[0].getProperty("class")).replace('tick', 'tick active'));
		}
		
		if(wrapper.getElementsBySelector(".gk_is_text_bg").length > 0){
			var text_block = wrapper.getElementsBySelector(".gk_is_text_bg")[0];
			wrapper.getElementsBySelector(".gk_is_text_item").each(function(elmt,i){contents[i] = elmt.innerHTML;});
		}
		
		if($E(".outter_readmore", wrapper)){
			$E(".outter_readmore", wrapper).addEvent("click", function(){
				window.location.href = links[$G['actual_slide']];
			});
		}
		
		var amount_c = contents.length-1;
		$G['actual_slide'] = 0;
		
		if(wrapper.getElementsBySelector(".gk_is_text")[0]) wrapper.getElementsBySelector(".gk_is_text")[0].innerHTML = contents[0];
		
		if(autoanimation == 1){
			gk_is_anim(wrapper,slides,contents,elID,animation_interval,animation_slide_speed,"right",true,animation_slide_type, $G, ticks_array);
		}
		// ----------
		}}).periodical(250);
	});
});

function gk_is_text_anim(wrapper,contents,as,ass){
	var txt = wrapper.getElementsBySelector(".gk_is_text",wrapper)[0];
	if(txt){
		new Fx.Opacity(txt,{duration: ass/2}).start(1,0);
		(function(){new Fx.Opacity(txt,{duration: ass/2}).start(0,1);txt.innerHTML = contents[as];}).delay(ass);
	}
}

function gk_is_anim(wrapper,slides,contents,elID,ai,ass,direct,play,animation_slide_type, $G, ticks_array){
	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);
			gk_is_text_anim(wrapper,contents,$G['actual_slide'],ass);	

				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);
				
			if(ticks_array.length > 0) ticks_array[actual_slide2].setProperty("class", (ticks_array[actual_slide2].getProperty("class")).replace('tick active', 'tick'));	
			if(ticks_array.length > 0) ticks_array[$G['actual_slide']].setProperty("class", (ticks_array[$G['actual_slide']].getProperty("class")).replace('tick', 'tick active'));
				
			(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_news_image_1_pause(elID, $G);}).delay(ass+ai);
	}
}

function gk_is_anim2(elID,wrapper,slides,contents,ass,direct,animation_slide_type, $G, ticks_array){
	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);
		gk_is_text_anim(wrapper,contents,$G['actual_slide'],ass);	
				
		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);
			
		if(ticks_array.length > 0) ticks_array[actual_slide2].setProperty("class", (ticks_array[actual_slide2].getProperty("class")).replace('tick active', 'tick'));
		if(ticks_array.length > 0) ticks_array[$G['actual_slide']].setProperty("class", (ticks_array[$G['actual_slide']].getProperty("class")).replace('tick', 'tick active'));
		
		(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;
}
