
/**
 * Funkce pro posouvani videa na uvodni strance
 */
//$(document).ready(function() {
//    homepagepage_init();
//});

$(document).ready(function() {
    init_homepage_slideshow();
});

function init_homepage_slideshow() {
    var isIE6;
    isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

    $("#homepage_slideshow_inner>div:first").removeClass("disable");
    $("#homepage_slideshow_inner>div:first").addClass("active");

    if(isIE6){
        $("#homepage_slideshow_inner>div:first img").css("display","none");
    } else {
        $("#homepage_slideshow_inner>div:first img").attr("src","images/slideshow/big.png");
        $("#homepage_slideshow_inner>div:first img").attr("style","");
    }
    var boxes = $("#homepage_slideshow_inner div.outer_box");
    var activeBox = boxes.filter(".active");
    var anchor = activeBox.children("a.heading");
    var innerBox = activeBox.children("div.inner_box");
    anchor.attr("href", innerBox.children("p").children("a").attr("href") );
    boxes.click(function(event) {
	var box = $(this);
	if (box.hasClass("active")) {
            var target = $(event.target);
            if(target.is('a') && !target.hasClass("heading")){
                return true;
            } else if(target.is('a') && target.hasClass("heading")){
                var url = target.parent().children(".inner_box").find("a").attr("href");
                target.attr("href",url );
                return true;
            } else {
                return false;
            }
	}
	homepage_slideshow_deactive(box, isIE6);
    });




    function homepage_slideshow_deactive(box, isIE6) {
	var activeBox = boxes.filter(".active");
	activeBox.children("div.inner_box").fadeOut("normal", function() {
	    var innerBox = $(this);
	    var anchor = activeBox.children("a.heading");
	    var img = activeBox.children("img.bg");
            anchor.attr("href", "#");
	    anchor.css("color", "#ffffff").animate({
		fontSize: "14px",
		top: "10px"
//	    });
	    }, "normal", null, function(){
		activeBox.removeClass("active").addClass("disable");
		anchor.attr("style", "");
	    });
            if(isIE6){
                img.css("display","none");
                activeBox.animate({
                    width: "340px",
                    height: "40px"
                }, "normal", null, function() {
                    homepage_slideshow_active_box(box, isIE6);
                });
            } else {
                img.animate({
                    width: "340px",
                    height: "40px"
                }, "normal", null, function() {
                    img.attr("src", "images/slideshow/small.png").attr("style", "");
                    homepage_slideshow_active_box(box, isIE6);
                });
            }
	});
    }

    function homepage_slideshow_active_box(box, isIE6) {
	var innerBox = box.children("div.inner_box");
	var anchor = box.children("a.heading");
	var img = box.children("img.bg");
	innerBox.hide();
        if(isIE6){
            box.animate({
                width: "470px",
                height: "170px"
            }, "normal", null, function() {
                img.css("display","none");
            });
        } else {
            img.animate({
                width: "470px",
                height: "170px"
            }, "normal", null, function() {
                img.attr("src", "images/slideshow/big.png").attr("style", "");
            });
        }
	anchor.attr("style", "font-weight", "bold");
        anchor.css("color","#FEE500").animate({
            fontSize: "21px",
            top: "25px"
	}, "normal", null, function(){
	    innerBox.fadeIn();
	})
	box.removeClass("disable").addClass("active");
	img.attr("style", "");
	anchor.attr("style", "");
        anchor.attr("href", innerBox.children("p").children("a").attr("href") );

    }


}
