/* ***************************************
Javascript developed by input 9 interactive
Link: http://www.input9.com

(c) 2011

Author: Bill Hanff

Last Modified: February 1, 2011
*************************************** */


function fadeIn(objID, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objID);
		if (opacity < 100) {
			opacity += 10;
			setOpacity(obj, opacity);
			window.setTimeout("fadeIn('"+objID+"',"+opacity+")", 50);
			}
		}
	}

function altAudio(){
		//alert('swap');
		if(jQuery.browser.msie || jQuery.browser.mozilla){

			$('#musicplayer').html('');

			var flashvars = {};
			flashvars.mp3file = "assets_mp3/test.mp3";
			//flashvars.autoplay = "true";
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("assets_mp3/button2.swf", "musicplayer", "40", "32", "8.0.0", false, flashvars, params, attributes);

			//$('#musicplayer').html(altAudioTxt);
		}
	}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.99:opacity; 
	obj.style.filter = "alpha(opacity:"+opacity+")"; // IE/Win
	obj.style.KHTMLOpacity = opacity/100; // Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100; // Older Mozilla and Firefox
	obj.style.opacity = opacity/100;	// Safari 1.2, newer Firefox and Mozilla, CSS3
	}
	
	
function showhide(divID){
		var node = document.getElementById(divID);
		if(node.className == "hide"){
			node.className = "show";
			fadeIn(divID, 0);
		} else {
			node.className = "hide";
		}
	}
	
	
function externalLinks() {
			var links = document.getElementsByTagName('a');// Fetch all the anchor elements in the document.
			for (var i = links.length; i != 0; i--) { // Loop through the a elements
				var a = links[i-1]; // Pull out the element for this iteration.
				if (!a.href) continue; // If the element doesn't have an href, skip it.
				if (a.className && a.className.indexOf('external') != -1){
						a.target = '_blank';
				}
			}
		}

function getURLDetails(url){
	findurl = url+'';
	if(findurl.indexOf('#')!=-1){
		var urlInitSplit = findurl.split('#');
		var urlItems = urlInitSplit[1];
		var urlScndSplit = urlItems.split('/');
		if(urlScndSplit[1] && urlScndSplit[1] != currentLanguage){
			setLanuguage(urlScndSplit[1]);
			}
		if(urlScndSplit[2] && urlScndSplit[2] != currentPage){
			currentPage = urlScndSplit[2];
			//setPage(urlScndSplit[2]);
			}
		if(urlScndSplit[2] && urlScndSplit[2] != currentPage){
			currentPage = urlScndSplit[2];
			//setPage(urlScndSplit[2]);
			}
	} else {
		return null;
	}
}

function setURL(){
	window.location = '#/'+currentLanguage+'/'+currentPage;
}

function setPage(pageid){
	window.location = '#/'+$('#currentlanguage').html()+'/'+pageid;
	$("#bgimg").fadeOut("slow");
	//alert(pageid);
	//$("#bgimg").attr("src", 'projectimages/test3.jpg');
	}
	
	
function setLanuguage(lang){
	if(currentLanguage != lang){
			$('#currentlanguage').html(lang);
			currentLanguage = lang;
			$.ajax({ url: 'navlanguage.php?lang='+lang, context: document.body, success: function(data){
				//alert(data);
				$("#mainnav").css({display: "none"});
				$('#mainnav').html(data);
				$('#mainnav').fadeIn('fast');
		
				$("#mainnav div").hover(
					function(){
						if($(this).find('ul:first').css('display')=='none'){
							$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(129);
						}
					},
					function(){ 
						if($(this).find('ul:first').css('display')=='block'){
							$(this).find('ul:first').css({visibility: "visible"}).slideUp(129);
						}
					}
				);
			}});
		setURL();
		}
	}

$(document).ready(function() {
	/*
	$("#bgimg").hide();
	$("#bgimg").bind("load", function (){  
		setImg();
		$(this).fadeIn("slow");
	});
	*/
});

$(window).resize(function(){ setImg(); setCS(); });

function setCS(){
		var winH = $(window).height();
		//alert(Math.round((winH-182)/2)+'px');
		$("#comingsoonwrap").css('marginTop', Math.round((winH-182)/2)+'px');
	}

function setImg(){
		var imgW = $("#bg img").width();
		var imgH = $("#bg img").height();
		var winW = $(window).width();
		var winH = $(window).height();
		var finW = winW+8;
		var finH = winH+8;

		if(finH < ((finW*imgH)/imgW) ){
			$("#bg img").width(finW);
			$("#bg img").height( Math.round((finW*imgH)/imgW) );
		} else {
			$("#bg img").height(finH);
			$("#bg img").width( Math.round((finH*imgW)/imgH));
		}
		
		$("#bg img").css('margin-left', Math.round(($("#bg img").width()-winW)*-0.5)+'px');
		$("#bg img").css('margin-top', Math.round(($("#bg img").height()-winH)*-0.5)+'px');
	}


setInterval ( "doSomething()", 5000 );

function nextImage(){
	var bgimgID = 'img'+currentImg;
	var bgimgIDLabel = '#'+bgimgID;

	lastID = currentID;
	currentID = bgimgID;
	//alert(bgimgID);
	$(lastID).css('z-index', 0);
	
	var bgimg = document.createElement("img");
	bgimg.src = imgSet[currentImg][0];
	$('#designedBy span').html(imgSet[currentImg][1]);
	$('#designedBy').hide(); 

	bgimg.id = bgimgID;
	bgimg.style.zIndex = imgSet.length;
	$("#bg").append(bgimg);
	
	if($.browser.msie){  $(bgimg).hide();  }else{  bgimg.className = 'imgunloaded';  }
	
	$(bgimgIDLabel).bind("load", function (){  
		$('#designedBy').fadeIn(); 
		setImg();
		
		
		if($.browser.msie){
			$(this).fadeIn(2000, function(){ $('#'+lastID).remove(); });
		}else{
			$("#bg img").removeClass();
			$("#bg img").addClass('imgloaded');
			window.setTimeout(function(){ $('#'+lastID).remove(); }, 1200);
		}

	});
	
	currentImg++;
	if(currentImg == imgSet.length){ currentImg = 0; }
}

$(document).ready(function() {
		setCS();
		//$("#comingsoonwrap").effect('slide', {to: {width:520}, }, 500, callback );
 		$('#comingsoonwrap').animate({width:'520px'}, 800, 'linear', function(){
			var bgimg = document.createElement("img");
			bgimg.src = imgSet[currentImg][0];
			$('#designedBy span').html(imgSet[currentImg][1]);

			bgimg.id = 'img'+currentImg;
			bgimg.style.zIndex = currentImg;
			$("#bg").append(bgimg);

			if($.browser.msie){  $("#bg img").hide();  }else{  bgimg.className = 'imgunloaded';  }

			currentID = 'img'+currentImg;
			$("#bg img").bind("load", function (){  
				setImg();
				if($.browser.msie){  $(this).fadeIn(2000);  }else{  $("#bg img").addClass('imgloaded');  }
				
		 		$('#designedBy').fadeIn();
				});

			currentImg++;
			setInterval("nextImage()", 8000);
		});
	}
);


var shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};

/*
var duration = 1000;
var easing = 'linear';
var callback = function(){};
 
/ * #1 * /
jQuery('something').animate({prop:1}, duration, easing, callback);
 
/ * #2 * /
jQuery('something').animate({prop:1},{
    easing: easing,
    duration: duration,
    complete: callback
});

*/
