/*
	$.onElementReady("#header", function() {
		
		
	}
*/
$(function() {
	var iPhoneOS = false;
	if (navigator.userAgent.match(/iPhone/i) ||
		navigator.userAgent.match(/iPod/i)) {
		iPhoneOS = true;
	}
	$("link").each(
		function() {
			var iphoneCSS = "";
			// remove site.css if iPhone
			if (this.href.indexOf("css/site.css") != -1) {
				if (iPhoneOS) {
					iphoneCSS = this.href.substring(0,this.href.indexOf("site.css"));
					this.href = iphoneCSS + "iphone.css";
				}
			}
		}
	);
	
	// populate mailto link
	$(".contactus a.contactemail").attr("href", "mailto:info@nouvelleniche.com?subject=www.nouvelleniche.com - Contact Us")
	.text("info@nouvelleniche.com");
	$(".contactus a.supportemail").attr("href", "mailto:support@nouvelleniche.com?subject=www.nouvelleniche.com - Support")
	.text("support@nouvelleniche.com");
	
	if (!iPhoneOS) {
		var changeDisplay = setInterval("rotateDisplay()", 10000);
	}
	// convert telephone number into phone link
	/*
	var phoneNum = $(".contactus a.tel").text();
	var phoneLink = phoneNum.replace(" ", ""); 
	$(".contactus a.tel").attr("href", "tel:" + phoneLink).click(function(event) {
		// follow link if iPhone or iPod Touch
		if (navigator.userAgent.match(/iPhone/i) || 
		navigator.userAgent.match(/iPod/i)) {
			// hide URL bar
			//window.scrollTo(0,1);
			return;
		}
		event.preventDefault();
	});
	*/
});

var increment = 0;

function rotateDisplay() {
	var display2 = $("#portfolio .infrasystems")[0].style.display;
	
	if (increment == 0) {
		if($.browser.msie) {
			$("#portfolio .themeclockfree").hide();
			$("#portfolio .themeclockalarm").hide();
			$("#portfolio .peaball").hide();
			$("#portfolio .infrasystems").show();
		} else {
			$("#portfolio .themeclockfree").fadeOut(750);
			$("#portfolio .themeclockalarm").fadeOut(750);
			$("#portfolio .peaball").fadeOut(750);
			$("#portfolio .infrasystems").fadeIn(2500);	
		}		
	} // end if (increment == 0);
		
	if (increment == 1) {
		if($.browser.msie) {
			$("#portfolio .themeclockfree").hide();
			$("#portfolio .themeclockalarm").show();
			$("#portfolio .infrasystems").hide();
			$("#portfolio .peaball").hide();
		} else {
			$("#portfolio .themeclockfree").fadeOut(750);
			$("#portfolio .themeclockalarm").fadeIn(2500);
			$("#portfolio .infrasystems").fadeOut(750);
			$("#portfolio .peaball").fadeOut(750);	
		}		
	} // end if (increment == 1);
	
	if (increment == 2) {
		if($.browser.msie) {
			$("#portfolio .peaball").show();
			$("#portfolio .themeclockfree").hide();
			$("#portfolio .themeclockalarm").hide();
			$("#portfolio .infrasystems").hide();
		} else {
			$("#portfolio .peaball").fadeIn(2500);
			$("#portfolio .themeclockfree").fadeOut(750);
			$("#portfolio .themeclockalarm").fadeOut(750);
			$("#portfolio .infrasystems").fadeOut(750);	
		}		
	} // end if (increment == 2);
	
	if (increment == 3) {
		if($.browser.msie) {
			$("#portfolio .themeclockfree").show();
			$("#portfolio .themeclockalarm").hide();
			$("#portfolio .infrasystems").hide();
			$("#portfolio .peaball").hide();
		} else {
			$("#portfolio .themeclockfree").fadeIn(2500);
			$("#portfolio .themeclockalarm").fadeOut(750);
			$("#portfolio .infrasystems").fadeOut(750);	
			$("#portfolio .peaball").fadeOut(750);	
		}
		// reset counter
		increment = 0;
		return;		
	} // end if (increment == 3);
	
	increment++;
} // end rotateDisplay()
