﻿function slideSwitch() {
    var $active = $('.our_designs_all a.active');
    if ($active.length == 0) $active = $('.our_designs_all a:last');
    var $next = $active.next().length ? $active.next()
        : $('.our_designs_all a:first');
    $active.addClass('last-active');
    $next.addClass('active');
    $active.removeClass('active last-active');
    var image = $next.attr("rel");
    var title = $next.attr("title");
    var href = $next.attr("href");
    
    
    $(".our_designs_ph").css('opacity', "1.0");
    $(".our_designs_ph_bg").html('<a class="our_design_img" href="'+href+'"><img alt="'+title+'" src="'+image+'" /></a><span class="our_design_title">'+title+'</span><a class="our_design_btn" href="'+href+'">לצפיה בפרויקט</a>');
    $(".our_designs_ph").animate({ opacity: "0.0" }, 800, function() {
		$(".our_designs_ph").html($(".our_designs_ph_bg").html());
	});
	
    $active.removeClass('active last-active');
   
    
    var $active2 = $('.our_sucsess_all a.active');
    if ($active2.length == 0) $active2 = $('.our_sucsess_all a:last');
    var $next2 = $active2.next().length ? $active2.next()
        : $('.our_sucsess_all a:first');
    $active2.addClass('last-active');
    $next2.addClass('active');
    $active2.removeClass('active last-active');
    var image2 = $next2.attr("rel");
    var title2 = $next2.attr("title");
    var href2 = $next2.attr("href");
    var desc2 = $next2.html();
    
    $(".our_sucsess_ph").css('opacity', "1.0");
    $(".our_sucsess_ph_bg").html('<a class="our_sucsess_img" href="'+href2+'"><img alt="'+title2+'" src="'+image2+'"  /></a><span class="our_sucsess_title">'+title2+'</span><span class="our_sucsess_content">'+desc2+'</span><a class="our_sucsess_btn" href="'+href2+'">לצפיה בפרויקט</a>');
    $(".our_sucsess_ph").animate({ opacity: "0.0" }, 800, function() {
		$(".our_sucsess_ph").html($(".our_sucsess_ph_bg").html());
	});
    $active2.removeClass('active last-active');
}

$(function() {
    //preload images
    $(".our_designs_all a").each(
		function(intIndex) {
		    jQuery("<img>").attr("src", $(this).attr("rel"));
		}
	);
	
	//preload images
    $(".our_sucsess_all a").each(
		function(intIndex) {
		    jQuery("<img>").attr("src", $(this).attr("rel"));
		}
	);
	
	//preload images
    $(".guru_all a").each(
		function(intIndex) {
		    jQuery("<img>").attr("src", $(this).attr("rel"));
		}
	);
	
    var $first = $('.our_designs_all a:first');
    $first.addClass('active');
    var $first2 = $('.our_sucsess_all a:first');
    $first2.addClass('active');
    var $first3 = $('.guru_all a:first');
    $first3.addClass('active');
    slideSwitch();
    stop_interval = setInterval("slideSwitch()", 6000);
   

    $(".guru_right").click(function() {
        var $active3 = $('.guru_all a.active');
        if ($active3.length == 0) $active3 = $('.guru_all a:last');
        var $next3 = $active3.next().length ? $active3.next()
            : $('.guru_all a:first');
        $active3.addClass('last-active');
        $next3.addClass('active');
        $active3.removeClass('active last-active');
        var image3 = $next3.attr("href");
        var title3 = $next3.html();
        
        $(".guru_ph").html($(".guru_ph_bg").html());
        $(".guru_ph").css('opacity', "1.0");
        $(".guru_ph_bg").html('<img alt="'+title3+'" src="'+image3+'" width="210px" />');
        $(".guru_ph").animate({ opacity: "0.0" }, 1200, function() { });
        $active3.removeClass('active last-active');
        return false;
    });

    $(".guru_left").click(function() {
        
        var $active3 = $('.guru_all a.active');
        if ($active3.length == 0) $active3 = $('.guru_all a:last');
        var $next3 = $active3.next().length ? $active3.next()
            : $('.guru_all a:first');
        $active3.addClass('last-active');
        $next3.addClass('active');
        $active3.removeClass('active last-active');
        var image3 = $next3.attr("href");
        var title3 = $next3.html();
        
        $(".guru_ph").html($(".guru_ph_bg").html());
        $(".guru_ph").css('opacity', "1.0");
        $(".guru_ph_bg").html('<img alt="'+title3+'" src="'+image3+'" width="210px" />');
        $(".guru_ph").animate({ opacity: "0.0" }, 1200, function() { });
        $active3.removeClass('active last-active');
        return false;
    }); 

});






