/**
 * @author MPJ 2010
 */


$(document).ready(function(){
	// PNG-Fix for jQuery
	if(jQuery().supersleight) {
		if (jQuery.browser.msie && parseInt(jQuery.browser.version) < 7 && parseInt(jQuery.browser.version) > 4) {	
			$('body').supersleight({shim: 'bo_splash_files/img/trans.gif'});
		};
	}

	var slide = new startSlider();
	slide.start();

//	function hoverScale(){
//		var origWidth;
//		var origHeight;
//		$("#navs a img").hover(function(){
//			$(this).attr("width", function(){
//				return ((origWidth=this.width) * 1.2);
//			});
//			$(this).attr("height", function(){
//				return ((origHeight = this.height) * 1.2);
//			});
//		}, function(){
//			
//		});
//	}
//	hoverScale();
	
}); // Document Ready END ---------------------------------

// On window load
$(window).bind(
		'load',
		function() {
			preloadImgs("img.activate", "", [
					"bo_splash_files/img/bo_splash_enter_gallery_active.png",
					"bo_splash_files/img/bo_splash_enter_company_active.png" ]);
});

/*
 * IMG Preloader ------------- 
 * - sel: Image selector f.e.: img.activate or img.preload 
 * - appendix: for automatic preloading of hover-files f.e.: "_active" 
 * - manList: Manual Array of img-paths to be preloaded. 
 * - Leave Appendix-Parameter empty, for manual Mode only.
 */
function preloadImgs(sel, appendix, manList) {
	var preload = new Array();
	if(appendix != ""){
		$(sel).each(function() {
			s = $(this).attr("src").replace(/\.(.+)$/i, appendix + ".$1");
			preload.push(s);
		});
	}

	for (key in manList) {
		preload.push(manList[key]);
	}
	var img = document.createElement('img');
	$(img).bind('load', function() {
		if (preload[0]) {
			this.src = preload.shift();
		}
	}).trigger('load');
}


/*
 * IMG-Slider MPJ
 */
function startSlider()
{
	
	var settings = {
			"jsonPath" : "bo_splash_files/slides.json",
			"slidebar" : {
				"selector" : "#picslides",
				"wrapWidth": "1024"
			},
			"cache" : {
				"json" : {},
				"slideWidth" : ""
			}
	};
	
	var globJson = {};
	var globWidth = '';
	var globSpeed = '30000';
	
	this.start = function() {
		this.getWidth();
	};
	
	function ani(){
		$(settings.slidebar.selector).animate({
//			left : -(settings.cache.slideWidth-settings.slidebar.wrapWidth)
			left : -(globWidth-settings.slidebar.wrapWidth)
		}, 
		30000, 
		'linear',
		
		function() {
			$(this).animate({
				left : 0
			},
			30000, 
			'linear',
				function() {ani();}
			);
		}
		
		
		);
	};
	
	this.getWidth = function () {
		$.ajax({
			url: settings.jsonPath,
			dataType: 'json',
			success: function(data) {
//				settings.cache.json = data;
//				settings.cache.slideWidth = calcWidth(data);
//				$('#picslides').css("width",settings.cache.slideWidth);
				globJson = data;
				globWidth = calcWidth(data);
				$('#picslides').css("width",globWidth);
			},
			complete: function(data) {
				ani();
			},
			error: function(a,b,c) {
				alert('Error: '+a+b+c);
			}
		});
	};

	function calcWidth(json) {
		var widths = 0;
		for(var key in json){
			widths += json[key].width;
		}
		return widths;		
	};

	
}
	









//----------- / Helper Functions 
		
		function dump(obj) {
			var str = "";
			for (prop in obj) {
				str += prop + " : " + obj[prop] + "<br>\n";
			}
			return str;
		}
