var fadeIndex = 0;
var fadeTimer = null;

function slideshow() {
    fadeIndex += 1;
    if(fadeIndex>=$(fadeImgs.images).length)
        fadeIndex = 0;        
        
    var src = fadeImgs.images[fadeIndex].src;
    $("#imagefade img:first").attr("src",src);                                        
    $("#imagefade img:last").fadeOut(2500,function(){ 
        $("#imagefade img:last").attr("src",src);
        $("#imagefade img:last").show();
    });
    
}      

jQuery (function(){    
    Shadowbox.init();
	var height = $('#people_images').total_height();
	$('#person_copy_wrap').height(800);
    $('.person_image a').click(function(){
    	if ($(this).hasClass("bottom")){
    		updateIndexes(this, '.person_copy', 1);
    	}    else {
    		updateIndexes(this, '.person_copy', 0);
    	}        
        return false;
    });
	
	$("#imagefade").load(function(){      
        var img = $('<img src="" alt="" />');    
        $(img).attr("src",fadeImgs.images[0].src);
        $(this).append(img);              
        fadeTimer = setInterval("slideshow()",6000);
    }).trigger("load");  
    
    $("#navigation li").hover(
        function() {               
            $(this).find("ul:first").show();    
        },
        function() {                
            $(this).find("ul:first").hide(); 
        }
    );
    
    $("#rotating-text").cycle({
        timeout:            6000    
    });
    
    $("#car-imagefade").cycle({
        timeout:            7000
    });
    
    /*$("#imagefade").cycle({
        timeout:            7000
    });*/

});

function updateIndexes(el, cls, btm) {
    var href = $(el).attr('href');
    var date = new Date();
    var curDate = null;
    $(cls).slideUp ('slow', function (){
        $.post('/ajax', 
        {
            'act': 'getpage', 
            'href': href
        }, 
        function(data){       
            if(data.error) {
                alert(data.error);
                return;
            }

            $(cls).html(data.result.content);
            $(cls).slideDown ('slow', 'swing');
            if (btm == 1)
 			{
 			$(cls).addClass("bottom");
 			} else {
 			$(cls).removeClass("bottom");
 			}
        },'json');  
    });      
      
    var complete = true;
    return false;
};
