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




var cur_indexSlides=0;
var completedLdSlides=false;
var msldImages = new Array();

msldImages[0]='';

function correctLastItem() {
msldImages[0]=msldImages[msldImages.length-1];
msldImages.remove(-1);
}

function addImgSlides(theUrl) {
msldImages[msldImages.length]=theUrl;
//console.log (msldImages.length);
//console.log (theUrl);
}



function LoadNextSlideImg() { //console.log ('ok '+cur_indexSlides+"/"+msldImages.length+"/"+slideSegs[1]);
	if (completedLdSlides==true) {return;}
	
	for (var aa=0; aa<slideSegs.length; aa++) {
	
		if (cur_indexSlides<slidesCounts[aa] ) {
		
			
		    var dter=slideSegs[aa]+cur_indexSlides;
			
			
			var sldimg=document.getElementById('sldimg'+dter);
			sldimg.src=msldImages[dter]; 
			//console.log (dter+":"+msldImages[dter]);
		}
		
	}
	
	cur_indexSlides=cur_indexSlides+1;

	if (cur_indexSlides >= msldImages.length) {
	completedLdSlides=true;
	} else {
	setTimeout("LoadNextSlideImg()",4000);
	}
}


window.addEvent("load", function () {

//console.log ('load1');


    $$(".gk_news_image_1_wrapper").each(function (q) {
        var r = q.getProperty("id");
        var s = $(r);
        var t = $Gavick[r];
        var u = t['anim_speed'];
        var v = t['anim_interval'];
        var w = t['autoanim'];
        var y = t['anim_type'];
        var z = t['anim_type_t'];
        var A = t['thumbnail_width'];
        var B = t['thumbnail_margin'];
        var C = t['thumbnail_border'];
        var D = t['thumbnail_border_color'];
        var E = t['thumbnail_border_color_inactive'];
        var F = t['bgcolor'];
        var G = t['opacity'];
        var H = [];
        var I = [];
        var J = [];
        var K = ($E('.gk_news_image_1_preloader', s)) ? false : true;
        if ($E('.gk_news_image_1_preloader', s)) {
            var L = [];
            $ES('.gk_news_image_1_slide', s).each(function (a, i) {
                J.push(a.getProperty('title'));
                
				//console.log (a.innerHTML);
				addImgSlides(a.innerHTML);
				
				var b = new Element('img', {
                    //"src": a.innerHTML, //opt akm
					"src":'#',
                    "alt": a.getProperty('title'),
                    "class": a.getProperty('class'),
					"id": a.getProperty('id'), /*akm*/
                    "style": a.getProperty('style')
                });
                L.push(b);
                b.injectAfter(a);
                a.remove()
            });
            var M = (function () {
                var b = 0;
                L.each(function (a, i) {
                    if (a.complete) b++
                });
                if (b == L.length) {
                    $clear(M);
                    K = b;
                    (function () {
                        new Fx.Opacity($E('.gk_news_image_1_preloader', s)).start(1, 0)
                    }).delay(400)
                }
            }).periodical(200)
        }
        var N = (function () {
            if (K) {
                $clear(N);
                if (window.ie) {
                    if ($E(".gk_news_image_1_text_bg", s)) $E(".gk_news_image_1_text_bg", s).setOpacity(G.toFloat())
                }
                s.getElementsBySelector(".gk_news_image_1_slide").each(function (a, i) {
                    H[i] = a;
                    if (t['clickable_slides'] == 1) {
                        a.addEvent("click", function () {
                            window.location = a.getProperty('alt')
                        });
                        a.setStyle("cursor", "pointer")
                    }
                });
                H.each(function (a, i) {
                    if (i != 0) a.setOpacity(0)
                });
                var c = [];
                if ($E('.gk_news_image_1_tick_buttons', s)) {
                    $ES('.tick', s).each(function (a, x) {
                        c[x] = a;
                        a.addEvent("click", function () {
                            gk_news_image_1_anim2(j, r, s, H, I, u, x, z, y, t, c)
                        })
                    });
                    c[0].setProperty("class", (c[0].getProperty("class")).replace('tick', 'tick active'))
                }
                if (s.getElementsBySelector(".gk_news_image_1_text_bg").length > 0) {
                    var d = s.getElementsBySelector(".gk_news_image_1_text_bg")[0];
                    s.getElementsBySelector(".gk_news_image_1_news_text").each(function (a, i) {
                        I[i] = a.innerHTML
                    });
                    if ($E('.gk_news_image_1_tb', s)) {
                        var f = $E('.gk_news_image_1_tb', s);
                        var g = $E('.gk_news_image_1_tb_prev', f.getParent());
                        var h = $E('.gk_news_image_1_tb_next', f.getParent());
                        var j = $ES('.gk_news_image_1_thumb', f);
                        var k = 0;
                        j[0].setStyles({
                            "border": C + "px solid " + D
                        });
                        j.each(function (a, i) {
                            a.addEvent("click", function () {
                                gk_news_image_1_anim2(j, r, s, H, I, u, i, z, y, t, c)
                            })
                        });
                        if ((j.length * (A + (2 * B) + (2 * C))) < d.getSize().size.x) {
                            g.setStyle("display", "none");
                            h.setStyle("display", "none");
                            f.setStyle("width", d.getSize().size.x + "px")
                        } else {
                            var l = Math.floor((f.getStyle("width").toInt() - (2 * B)) / (A + (2 * B) + (2 * C))) - 1;
                            var m = new Fx.Scroll(f, {
                                transition: Fx.Transitions.linear,
                                duration: 50
                            });
                            var n, timer_right;
                            var o = 0;
                            g.addEvent("mouseenter", function () {
                                if (o > 0) {
                                    n = (function () {
                                        if (o > 0) {
                                            o -= 5;
                                            m.scrollTo(o, 0)
                                        } else {
                                            $clear(n);
                                            o = 0;
                                            m.toLeft()
                                        }
                                    }).periodical(50)
                                }
                            });
                            h.addEvent("mouseenter", function () {
                                var a = $E(".gk_news_image_1_tbo", f).getSize().size.x;
                                if (o < a) {
                                    timer_right = (function () {
                                        if (o < a) {
                                            o += 5;
                                            m.scrollTo(o, 0)
                                        } else {
                                            $clear(timer_right);
                                            o = a;
                                            m.toRight()
                                        }
                                    }).periodical(50)
                                }
                            });
                            g.addEvent("mouseout", function () {
                                $clear(n);
                                $clear(timer_right)
                            });
                            h.addEvent("mouseout", function () {
                                $clear(timer_right);
                                $clear(n)
                            })
                        }
                        j.each(function (b, i) {
                            b.addEvent("click", function () {
                                j.each(function (a) {
                                    a.setStyle("border", C + "px solid " + E)
                                });
                                b.setStyle("border", C + "px solid " + D)
                            })
                        })
                    }
                }
                if ($E(".gk_news_image_1_prev", s)) {
                    $E(".gk_news_image_1_prev", s).addEvent("click", function (e) {
                        var a = new Event(e);
                        a.preventDefault();
                        gk_news_image_1_anim2(j, r, s, H, I, u, ((t['actual_slide'] > 0) ? t['actual_slide'] - 1 : H.length - 1), z, y, t, c)
                    })
                }
                if ($E(".gk_news_image_1_next", s)) {
                    $E(".gk_news_image_1_next", s).addEvent("click", function (e) {
                        var a = new Event(e);
                        a.preventDefault();
                        gk_news_image_1_anim2(j, r, s, H, I, u, ((t['actual_slide'] < H.length - 1) ? t['actual_slide'] + 1 : 0), z, y, t, c)
                    })
                }
                if ($E(".gk_news_image_1_play", s)) {
                    $E(".gk_news_image_1_play", s).addEvent("click", function (e) {
                        var a = new Event(e);
                        a.preventDefault();
                        gk_news_image_1_anim(s, H, I, j, r, v, u, "right", true, z, y, t, c);
                        $E(".gk_news_image_1_play", s).setStyle("display", "none");
                        $E(".gk_news_image_1_pause", s).setStyle("display", "block")
                    })
                }
                if ($E(".gk_news_image_1_pause", s)) {
                    $E(".gk_news_image_1_pause", s).addEvent("click", function (e) {
                        var a = new Event(e);
                        a.preventDefault();
                        gk_news_image_1_pause(r, t)
                    })
                }
                if ($E(".outter_readmore", s)) {
                    $E(".outter_readmore", s).addEvent("click", function () {
                        window.location.href = J[t['actual_slide']]
                    })
                }
                var p = I.length - 1;
                t['actual_slide'] = 0;
                if (s.getElementsBySelector(".gk_news_image_1_text")[0]) s.getElementsBySelector(".gk_news_image_1_text")[0].innerHTML = I[0];
                if (w == 1) {
                    gk_news_image_1_anim(s, H, I, j, r, v, u, "right", true, z, y, t, c);
                    if ($E(".gk_news_image_1_play", s)) $E(".gk_news_image_1_play", s).setStyle("display", "none")
                } else {
                    if ($E(".gk_news_image_1_pause", s)) $E(".gk_news_image_1_pause", s).setStyle("display", "none")
                }
            }
        }).periodical(250)
    })
	
	correctLastItem();
	LoadNextSlideImg();
});

function gk_news_image_1_text_anim(a, b, c, d, e) {
    var f = a.getElementsBySelector(".gk_news_image_1_text")[0];
    if (f) {
        if (d == 0) {
            new Fx.Opacity(f, {
                duration: e / 2
            }).start(1, 0);
            (function () {
                new Fx.Opacity(f, {
                    duration: e / 2
                }).start(0, 1);
                f.innerHTML = b[c]
            }).delay(e)
        } else f.innerHTML = b[c]
    }
}
function gk_news_image_1_anim(b, c, d, e, f, g, h, i, j, k, l, m, n) {
    var o = c.length - 1;
    if (!m['actual_animation']) {
        m['actual_animation'] = (function () {
            if (i == "left") var a = (m['actual_slide'] == 0) ? 0 : m['actual_slide'];
            if (i == "right") var a = (m['actual_slide'] == o) ? o : m['actual_slide'];
            if (i == "left")(m['actual_slide'] == 0) ? m['actual_slide'] = o : m['actual_slide'] -= 1;
            if (i == "right")(m['actual_slide'] == o) ? m['actual_slide'] = 0 : m['actual_slide'] += 1;
            c[m['actual_slide']].setStyle("z-index", o + 1);
            new Fx.Opacity(c[a], {
                duration: h
            }).start(1, 0);
            m['actual_animation_p'] = true;
            new Fx.Opacity(c[m['actual_slide']], {
                duration: h
            }).start(0, 1);
            gk_news_image_1_text_anim(b, d, m['actual_slide'], k, h);
            switch (l) {
            case 0:
                break;
            case 1:
                new Fx.Style(c[m['actual_slide']], 'margin-top', {
                    duration: h
                }).start((-1) * c[m['actual_slide']].getSize().size.y, 0);
                break;
            case 2:
                new Fx.Style(c[m['actual_slide']], 'margin-left', {
                    duration: h
                }).start((-1) * c[m['actual_slide']].getSize().size.x, 0);
                break;
            case 3:
                new Fx.Style(c[m['actual_slide']], 'margin-top', {
                    duration: h
                }).start(c[m['actual_slide']].getSize().size.y, 0);
                break;
            case 4:
                new Fx.Style(c[m['actual_slide']], 'margin-left', {
                    duration: h
                }).start(c[m['actual_slide']].getSize().size.x, 0);
                break
            }
            if (e) e[a].setStyles({
                "border": m['thumbnail_border'] + "px solid " + m['thumbnail_border_color_inactive']
            });
            if (e) e[m['actual_slide']].setStyles({
                "border": m['thumbnail_border'] + "px solid " + m['thumbnail_border_color']
            });
            if (n.length > 0) n[a].setProperty("class", (n[a].getProperty("class")).replace('tick active', 'tick'));
            if (n.length > 0) n[m['actual_slide']].setProperty("class", (n[m['actual_slide']].getProperty("class")).replace('tick', 'tick active'));
            (function () {
                c[m['actual_slide']].setStyle("z-index", m['actual_slide'])
            }).delay(h);
            (function () {
                m['actual_animation_p'] = false
            }).delay(h)
        }).periodical(h + g);
        (function () {
            if (!j) gk_news_image_1_pause(f, m)
        }).delay(h + g)
    }
}
function gk_news_image_1_anim2(a, b, c, d, e, f, g, h, i, j, k) {
    var l = d.length - 1;
    if (!j['actual_animation_p'] && g != j['actual_slide']) {
        var m = j['actual_slide'];
        j['actual_slide'] = g;
        d[j['actual_slide']].setStyle("z-index", l + 1);
        new Fx.Opacity(d[m], {
            duration: f
        }).start(1, 0);
        j['actual_animation_p'] = true;
        new Fx.Opacity(d[j['actual_slide']], {
            duration: f
        }).start(0, 1);
        gk_news_image_1_text_anim(c, e, j['actual_slide'], h, f);
        switch (i) {
        case 0:
            break;
        case 1:
            new Fx.Style(d[j['actual_slide']], 'margin-top', {
                duration: f
            }).start((-1) * d[j['actual_slide']].getSize().size.y, 0);
            break;
        case 2:
            new Fx.Style(d[j['actual_slide']], 'margin-left', {
                duration: f
            }).start((-1) * d[j['actual_slide']].getSize().size.x, 0);
            break;
        case 3:
            new Fx.Style(d[j['actual_slide']], 'margin-top', {
                duration: f
            }).start(d[j['actual_slide']].getSize().size.y, 0);
            break;
        case 4:
            new Fx.Style(d[j['actual_slide']], 'margin-left', {
                duration: f
            }).start(d[j['actual_slide']].getSize().size.x, 0);
            break
        }
        if (a) a[m].setStyles({
            "border": j['thumbnail_border'] + "px solid " + j['thumbnail_border_color_inactive']
        });
        if (a) a[j['actual_slide']].setStyles({
            "border": j['thumbnail_border'] + "px solid " + j['thumbnail_border_color']
        });
        if (k.length > 0) k[m].setProperty("class", (k[m].getProperty("class")).replace('tick active', 'tick'));
        if (k.length > 0) k[j['actual_slide']].setProperty("class", (k[j['actual_slide']].getProperty("class")).replace('tick', 'tick active'));
        (function () {
            d[j['actual_slide']].setStyle("z-index", j['actual_slide'])
        }).delay(f);
        (function () {
            j['actual_animation_p'] = false
        }).delay(f);
        gk_news_image_1_pause(b, j)
    }
}
function gk_news_image_1_pause(a, b) {
    var c = $(a);
    $clear(b['actual_animation']);
    b['actual_animation'] = false;
    if ($E(".gk_news_image_1_play", c)) $E(".gk_news_image_1_play", c).setStyle("display", "block");
    if ($E(".gk_news_image_1_pause", c)) $E(".gk_news_image_1_pause", c).setStyle("display", "none")
}
