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_news_image_1_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 animation_text_type = $G['anim_type_t'];
		var thumbnail_width = $G['thumbnail_width'];
		var thumbnail_margin = $G['thumbnail_margin'];
		var thumbnail_border = $G['thumbnail_border'];
		var thumbnail_border_color = $G['thumbnail_border_color'];
		var thumbnail_border_color_inactive = $G['thumbnail_border_color_inactive'];
		var base_bgcolor = $G['bgcolor'];
		var base_opacity = $G['opacity'];
		var slides = [];
		var contents = [];
		var links = [];
		var loadedImages = ($E('.gk_news_image_1_preloader', wrapper)) ? false : true;
	
		if($E('.gk_news_image_1_preloader', wrapper)){
			var imagesToLoad = [];
			
			$ES('.gk_news_image_1_slide',wrapper).each(function(el,i){
				links.push(el.getProperty('title'));
				var newImg = new Element('img',{
					"src":urldecode(el.innerHTML),
					"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_news_image_1_preloader', wrapper)).start(1,0);}).delay(400);
				}
			}).periodical(200);
		}
		
		var timerrr2 = (function(){
		if(loadedImages){
		$clear(timerrr2);
		// ----------	
		if(window.ie){
			if($E(".gk_news_image_1_text_bg", wrapper)) $E(".gk_news_image_1_text_bg",wrapper).setOpacity(base_opacity.toFloat());
		}
		
		wrapper.getElementsBySelector(".gk_news_image_1_slide").each(function(elmt,i){
			slides[i] = elmt;
			if($G['clickable_slides'] == 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_news_image_1_tick_buttons', wrapper)){
			$ES('.tick', wrapper).each(function(el,x){
				ticks_array[x] = el;
				
				el.addEvent("click",function(){
					gk_news_image_1_anim2(thumbs_array,elID,wrapper,slides,contents,animation_slide_speed,x,animation_text_type,animation_slide_type, $G, ticks_array);
				});
			});
			
			ticks_array[0].setProperty("class", (ticks_array[0].getProperty("class")).replace('tick', 'tick active'));
		}
		
		if(wrapper.getElementsBySelector(".gk_news_image_1_text_bg").length > 0){
			var text_block = wrapper.getElementsBySelector(".gk_news_image_1_text_bg")[0];
			wrapper.getElementsBySelector(".gk_news_image_1_news_text").each(function(elmt,i){contents[i] = elmt.innerHTML;});
		
			if($E('.gk_news_image_1_tb',wrapper)){
				var thmb_bar = $E('.gk_news_image_1_tb',wrapper);
				var prev = $E('.gk_news_image_1_tb_prev',thmb_bar.getParent());
				var next = $E('.gk_news_image_1_tb_next',thmb_bar.getParent());
				var thumbs_array = $ES('.gk_news_image_1_thumb',thmb_bar);
				
				var actual_thumb = 0;
				thumbs_array[0].setStyles({"border": thumbnail_border + "px solid " + thumbnail_border_color});
				
				thumbs_array.each(function(el,i){
					el.addEvent("click",function(){
						gk_news_image_1_anim2(thumbs_array,elID,wrapper,slides,contents,animation_slide_speed,i,animation_text_type,animation_slide_type, $G, ticks_array);
					});
				});
				
				if( (thumbs_array.length * (thumbnail_width+(2*thumbnail_margin)+(2*thumbnail_border))) < text_block.getSize().size.x){
					prev.setStyle("display","none");
					next.setStyle("display","none");
					thmb_bar.setStyle("width", text_block.getSize().size.x+"px");
				}else{
					var visible_thmb = Math.floor((thmb_bar.getStyle("width").toInt()-(2*thumbnail_margin)) / (thumbnail_width+(2*thumbnail_margin)+(2*thumbnail_border))) - 1;
					var thmb_slider = new Fx.Scroll(thmb_bar,{transition: Fx.Transitions.linear,duration: 50});
					var timer_left, timer_right;
					var position = 0;
				
					prev.addEvent("mouseenter",function(){
						if(position > 0){
							timer_left = (function(){
								if(position > 0){
									position-=5;
									thmb_slider.scrollTo(position,0);
								}else{
									$clear(timer_left);
									position = 0;
									thmb_slider.toLeft();
								}
							}).periodical(50);
						}
					});
					
					next.addEvent("mouseenter",function(){
						var xsize = $E(".gk_news_image_1_tbo",thmb_bar).getSize().size.x;
						if(position < xsize){
							timer_right = (function(){
								if(position < xsize){
									position+=5;
									thmb_slider.scrollTo(position,0);
								}else{
									$clear(timer_right);
									position = xsize;
									thmb_slider.toRight();
								}
							}).periodical(50);
						}
					});
					
					prev.addEvent("mouseout",function(){$clear(timer_left);$clear(timer_right);});
					next.addEvent("mouseout",function(){$clear(timer_right);$clear(timer_left);});
				}
				
				thumbs_array.each(function(el,i){
					el.addEvent("click",function(){
						thumbs_array.each(function(elmt){elmt.setStyle("border", thumbnail_border + "px solid " + thumbnail_border_color_inactive);});
						el.setStyle("border", thumbnail_border + "px solid " + thumbnail_border_color);
					});
				});
			}
		}
		
		if($E(".gk_news_image_1_prev", wrapper)){
			$E(".gk_news_image_1_prev", wrapper).addEvent("click",function(e){
				var event = new Event(e);event.preventDefault();
				gk_news_image_1_anim2(thumbs_array,elID,wrapper,slides,contents,animation_slide_speed,(($G['actual_slide'] > 0) ? $G['actual_slide']-1 : slides.length-1),animation_text_type,animation_slide_type, $G, ticks_array);
			});
		}
		
		if($E(".gk_news_image_1_next", wrapper)){
			$E(".gk_news_image_1_next", wrapper).addEvent("click",function(e){
				var event = new Event(e);event.preventDefault();
				gk_news_image_1_anim2(thumbs_array,elID,wrapper,slides,contents,animation_slide_speed,(($G['actual_slide'] < slides.length-1) ? $G['actual_slide']+1 : 0),animation_text_type,animation_slide_type, $G, ticks_array);
			});
		}
		
		if($E(".gk_news_image_1_play", wrapper)){
			$E(".gk_news_image_1_play", wrapper).addEvent("click",function(e){
				var event = new Event(e);event.preventDefault();
				gk_news_image_1_anim(wrapper,slides,contents,thumbs_array,elID,animation_interval,animation_slide_speed,"right",true,animation_text_type,animation_slide_type, $G, ticks_array);
				$E(".gk_news_image_1_play", wrapper).setStyle("display","none");
				$E(".gk_news_image_1_pause", wrapper).setStyle("display","block");
			});
		}
		
		if($E(".gk_news_image_1_pause", wrapper)){
			$E(".gk_news_image_1_pause", wrapper).addEvent("click",function(e){
				var event = new Event(e);event.preventDefault();
				gk_news_image_1_pause(elID, $G);
			});
		}
		
		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_news_image_1_text")[0]) wrapper.getElementsBySelector(".gk_news_image_1_text")[0].innerHTML = contents[0];
		
		if(autoanimation == 1){
			gk_news_image_1_anim(wrapper,slides,contents,thumbs_array,elID,animation_interval,animation_slide_speed,"right",true,animation_text_type,animation_slide_type, $G, ticks_array);
			if($E(".gk_news_image_1_play", wrapper)) $E(".gk_news_image_1_play", wrapper).setStyle("display","none");
		}else{
			if($E(".gk_news_image_1_pause", wrapper)) $E(".gk_news_image_1_pause", wrapper).setStyle("display","none");
		}
		// ----------
		}}).periodical(250);
	});
});

function gk_news_image_1_text_anim(wrapper,contents,as,type,ass){
	var txt = wrapper.getElementsBySelector(".gk_news_image_1_text")[0];
	if(txt){
		if(type == 0){	
			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);
		}else txt.innerHTML = contents[as];
	}
}

function gk_news_image_1_anim(wrapper,slides,contents,thumbs_array,elID,ai,ass,direct,play,type,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_news_image_1_text_anim(wrapper,contents,$G['actual_slide'],type,ass);	
				
			switch(animation_slide_type){
				case 0: break;
				case 1: new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.y,0);break;
				case 2: new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.x,0);break;
				case 3: new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.y,0);break;
				case 4: new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.x,0);break;
			}
				
			if(thumbs_array) thumbs_array[actual_slide2].setStyles({"border": $G['thumbnail_border'] + "px solid " + $G['thumbnail_border_color_inactive']});	
			if(thumbs_array) thumbs_array[$G['actual_slide']].setStyles({"border": $G['thumbnail_border'] + "px solid " + $G['thumbnail_border_color']});	
				
			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_news_image_1_anim2(thumbs_array,elID,wrapper,slides,contents,ass,direct,type,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_news_image_1_text_anim(wrapper,contents,$G['actual_slide'],type,ass);	
				
		switch(animation_slide_type){
			case 0: break;
			case 1: new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.y,0);break;
			case 2: new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start((-1)*slides[$G['actual_slide']].getSize().size.x,0);break;
			case 3: new Fx.Style(slides[$G['actual_slide']],'margin-top',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.y,0);break;
			case 4: new Fx.Style(slides[$G['actual_slide']],'margin-left',{duration: ass}).start(slides[$G['actual_slide']].getSize().size.x,0);break;
		}
				
		if(thumbs_array) thumbs_array[actual_slide2].setStyles({"border": $G['thumbnail_border'] + "px solid " + $G['thumbnail_border_color_inactive']});	
		if(thumbs_array) thumbs_array[$G['actual_slide']].setStyles({"border": $G['thumbnail_border'] + "px solid " + $G['thumbnail_border_color']});
			
		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_news_image_1_pause(elID, $G);
	}
}

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

function urldecode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brettz9.blogspot.com)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // %          note 1: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {};
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF'; 
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
 
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}					
