var fadeIndex = new Array();

var fadeImages = {
	"fade-header":[
		{"src":"/media/images/home_img_set/img1.jpg","desc":"test"},
		{"src":"/media/images/home_img_set/img2.jpg"},
		{"src":"/media/images/home_img_set/img3.jpg"},
		{"src":"/media/images/home_img_set/img4.jpg"}
	],
	"fade-index":[
		{"src":"/media/images/rightimg1.jpg","desc":""}
	],
	"fade-about-us":[
		{"src":"/media/images/rightimg2.jpg","desc":""}
	],
	"fade-auctions":[
		{"src":"/media/images/rightimg5.jpg","desc":""}
	],
	"fade-professional-services":[
		{"src":"/media/images/rightimg12.jpg","desc":""}
	],
	"fade-properties":[
		{"src":"/media/images/rightimg6.jpg","desc":""}
	],
	"fade-contact-us":[
		{"src":"/media/images/rightimg9.jpg","desc":""}
	]
};

Shadowbox.loadSkin('wcms', '/media/scripts/shadowbox/');

$(document).ready(function(){
	Shadowbox.init();
	show_clock();
	
	// External Links
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

	// Setup image faders
	$(".imagefade").each(function(){
		var id = $(this).attr("id");
		fadeIndex[id] = parseInt(0);

		if(typeof(fadeImages[id])!="object")
			return;
		
		var imgs = fadeImages[id];
		var img = $('<img src="" alt="" />');
		$(img).attr("src",imgs[0].src);
		$(this).append(img);

		if(typeof(imgs[0].desc)=="string")
			$(this).find("p").html(imgs[0].desc);
		
		setInterval(function(){
			var elm = document.getElementById(id);
			var total = imgs.length;
			fadeIndex[id]+=1;

			if(fadeIndex[id]==total)
				fadeIndex[id] = parseInt(0);
				
			$(elm).children("img:first").attr("src",imgs[fadeIndex[id]].src);
			$(elm).children("img:last").fadeOut("slow",function(){
				$(elm).children("img:last").attr("src",imgs[fadeIndex[id]].src);
				$(elm).children("img:last").show();
			});
			
			if(typeof(imgs[0].desc)=="string")
				$(elm).children("p").html(imgs[0].desc);
	 
		},10000);
	});

	/*// Setup image faders
	$(".imagefadexx").each(function(){
		var id = $(this).attr("id");
		fadeIndex[id] = parseInt(0);

		if(typeof(fadeImages[id])!="object")
			return;
		
		var imgs = fadeImages[id];
		var img = $('<img src="" alt="" />');
		$(img).attr("src",imgs[0].src);
		$(this).append(img);

		if(typeof(imgs[0].desc)=="string")
			$(this).find("p").html(imgs[0].desc);
	});*/

});
