/**
 * Created by Web-Logic
 * User: firs.yura@gmail.com
 */
$(function() {
    var click_stop = 0;
    $("#right_arr").live('click',function(){
        if (click_stop==0) {
            click_stop = 1;
            $(".indexbox").die('mouseover mouseout');
            $(".bl1, .bl2, .bl4").animate({
                left: '+=124',
                top: '+=120'
            },500, function() {
                var cl = $(this).attr('class');
                var re = /[\a-z ]+/;
                var new_cl = parseInt(cl.replace(re, ""))+1;
                $(this).attr('class','indexbox bl'+new_cl);
                $(this).attr('style','opacity:1;');
            });
            $(".bl3, .bl5, .bl6").animate({
                left: '+=124',
                top: '-=120'
            },500, function() {
                var cl = $(this).attr('class');
                var re = /[\a-z ]+/;
                var new_cl = parseInt(cl.replace(re, ""))+1;
                $(this).attr('class','indexbox bl'+new_cl);
                $(this).attr('style','opacity:1;');
            });
            $(".bl7").animate({
                opacity:0
            },250, function() {
                $(this).attr('class','indexbox bl1');
                $(this).animate({
                    opacity:1
                },250,function(){
                    $(this).attr('style','opacity:1;');
                    click_stop = 0;
                    $(".indexbox").live('mouseover mouseout',function(event){ blocks_opacity(this,event); });
                });
            });
        }
    });

    $("#left_arr").live('click',function(){
        if (click_stop==0) {
            click_stop = 1;
            $(".indexbox").die('mouseover mouseout');
            $(".bl2, .bl3, .bl5").animate({
                left: '-=124',
                top: '-=120'
            },500, function() {
                var cl = $(this).attr('class');
                var re = /[\a-z ]+/;
                var new_cl = parseInt(cl.replace(re, ""))-1;
                $(this).attr('class','indexbox bl'+new_cl);
                $(this).attr('style','opacity:1;');
            });
            $(".bl4, .bl6, .bl7").animate({
                left: '-=124',
                top: '+=120'
            },500, function() {
                var cl = $(this).attr('class');
                var re = /[\a-z ]+/;
                var new_cl = parseInt(cl.replace(re, ""))-1;
                $(this).attr('class','indexbox bl'+new_cl);
                $(this).attr('style','opacity:1;');
            });
            $(".bl1").animate({
                opacity:0
            },250, function() {
                $(this).attr('class','indexbox bl7');
                $(this).animate({
                    opacity:1
                },250,function(){
                    $(this).attr('style','opacity:1;');
                    click_stop = 0;
                    $(".indexbox").live('mouseover mouseout',function(event){ blocks_opacity(this,event); });
                });
            });
        }
    });
    var standardOpacityHook = jQuery.cssHooks.opacity.get
			jQuery.cssHooks.opacity.get = function( elem, computed ) {
				return standardOpacityHook(elem, computed).replace(",", ".");
			}
    $(".indexbox, #left_arr, #right_arr").live('mouseover mouseout',function(event){ blocks_opacity(this,event); });
    sildeOn = setTimeout('autoSlide()', 3000);
});
function autoSlide()
{
    $("#right_arr").click();
    slideOn = setTimeout('autoSlide()', 3000);
}
function blocks_opacity (elem,event) {

    if (event.type == 'mouseover') {
        clearTimeout(slideOn);
//        $(".indexbox").stop().not(elem).animate({opacity:0.5},500);
//        $(elem).stop().animate({opacity:1},500);
    } else {
        clearTimeout(slideOn);
        slideOn = setTimeout('autoSlide()', 3000)
//        $(".indexbox").stop().animate({opacity:1},500);
    }
}
