var resimsayac;
resimsayac = 2;
var resimsayac_home;
resimsayac_home = 2;
var resimsayac_load;
resimsayac_load = 2;



(function($) {
	var imgList = [];
	$.extend({
		preload: function(imgArr, option) {
			var setting = $.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(var i in imgArr) {
				imgList.push($("<img />")
					.attr("src", imgArr[i])
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	});
})(jQuery);



$(function() {
    $.preload([
        "http://www.hedefgrup.com/images/home-2.jpg","http://www.hedefgrup.com/images/home-3.jpg","http://www.hedefgrup.com/images/home-4.jpg","http://www.hedefgrup.com/images/home-5.jpg","http://www.hedefgrup.com/images/home-6.jpg","http://www.hedefgrup.com/images/home-7.jpg","http://www.hedefgrup.com/images/home-8.jpg","http://www.hedefgrup.com/images/home-9.jpg","http://www.hedefgrup.com/images/home-10.jpg","http://www.hedefgrup.com/images/home-11.jpg","http://www.hedefgrup.com/images/home-12.jpg"], {
        init: function(loaded, total) {
            //$("#indicator").html("Loaded: "+loaded+"/"+total);
        },
        loaded: function(img, loaded, total) {
			resimsayac_load++;
        },
        loaded_all: function(loaded, total) {
            resimsayac_load = 999;
        }
    });
});



function bgresize() {
	w_height = $(window).height();
	w_width = $(window).width();
	w_ratio = w_width/w_height;
	efektif_h = (w_height - $('#bgresim div:last img').height())/2;
	efektif_w = (w_width - $('#bgresim div:last img').width())/2;
	
	if(w_ratio>=1.6){
	$('#bgresim div:last img').width(w_width);
	$('#bgresim div:last img').height(w_width/1.6);
	//$('#bgresim div:last img').offset({ top: efektif_h});
	}
	else{
	$('#bgresim div:last img').width(w_height*1.6);
	$('#bgresim div:last img').height(w_height);	
	}
}
$(window).bind('resize', function() { 
	bgresize();
});
function bgresim() {
	if(resimsayac_home < resimsayac_load){
	if(resimsayac_home>12){ resimsayac_home=1; }
	$('#bgresim').append('<div id="bg-element-'+resimsayac+'" style="display:block; width:100%; height:100%; overflow:hidden; position:absolute; top:0; left:0; z-index:'+(-10000+resimsayac)+'"><img style="opacity:0;" src="images/home-'+resimsayac_home+'.jpg" /></div>');
	bgresize();
	
	
	
	$('#bgresim div:last img').animate({
    opacity: 1
	}, 2500, function() {
    $('#bgresim div:first').remove();
 	 });
	
	resimsayac++;
	resimsayac_home++;
	}
}


$(document).ready(function() {
	setInterval( "bgresim()", 8000 );
	bgresize();
})
