function slidesTagsReplace(slides_parent, current_slide_tag, new_slide_tag, slides_links){
    var slide_links = [];
    var slides_html = [];
    var slides = $(slides_parent).children("div").children(current_slide_tag);
    for (var j = 0; j < slides.length; j++) {
        if (current_slide_tag == "a") {
            slide_links[j] = $(slides).eq(j).attr("href");
        }
        slides_html[j] = $(slides).eq(j).html();
    }
    $(slides).remove();
    for (var j = 0; j < slides_html.length; j++) {
        $(slides_parent).children("div").eq(j).append("<" + new_slide_tag + ">" + "</" + new_slide_tag + ">");
        $(slides_parent).children("div").children(new_slide_tag).eq(j).html(slides_html[j]);
        if (new_slide_tag == "a") {
            $(slides_parent).children("div").children("a").eq(j).attr("href", slides_links[j]);
            $(slides_parent).children("div").children("a").eq(j).attr("rel", "prettyPhoto[mixed]");
        }
    }
    if (current_slide_tag == "a") {
        return slide_links;
    }
}
/*
function slidesTagsReplace(slides_selector, slides_links){
    var slide_links = [];
    var slides_html = [];
    var slides = slides_selector;
    for (var j = 0; j < slides.length; j++) {
        slides_html[j] = $(slides).eq(j).html();
		if ($(slides).attr("href")) {
            slide_links[j] = $(slides).eq(j).attr("href");
			$("<span></span>").insertAfter($(slides).eq(j)).html(slides_html[j]);
			$(slides).eq(j).remove();
        }
    }
	return slides_links;
}
*/
function initMultiSlider(){
    $(document).ready(function(){
        (function(){
            var top_slider_blocks = $("div.top_slide_block");// blocks for slideshow 
            var slider_blocks_parent = $("#top_slider_content"); // block which contains the slides
            var top_slider_interval = 5000;//ms
            var slide_hide_time = 800;//ms
            var slide_shift = $("div.top_slide_block").outerWidth(true);
            var timeout2;
            $(slider_blocks_parent).css("width", (top_slider_blocks.length + 1) * slide_shift + "px");
            function topSlider(){
                $(slider_blocks_parent).append($(slider_blocks_parent).children("div").eq(0).clone());
                var slides_links = [];
                slides_links = slidesTagsReplace($(slider_blocks_parent), "a", "span");
				//slides_links = slidesTagsReplace($(slider_blocks_parent).children().children("a"));
                $(slider_blocks_parent).animate({
                    left: -slide_shift + "px"
                }, slide_hide_time, function(){
                    $(slider_blocks_parent).children("div").eq(0).remove();
                    $(slider_blocks_parent).css("left", "0px");
                    slides_links.splice(0, 1);
                    slidesTagsReplace($(slider_blocks_parent), "span", "a", slides_links);
                    $(slider_blocks_parent).children().children("a").click(function(){
                        clearTimeout(timeout2);
                    });
					/*
                    $(slider_blocks_parent).children().children("a[rel='prettyPhoto[mixed]']").prettyPhoto({
                        theme: 'dark_rounded'
                    })
                   */ 
                });
                timeout2 = setTimeout(topSlider, top_slider_interval);
            }
            topSlider();
        })()
    })
}

initMultiSlider();

