/**
 * @author ianfarrell - Creative Freestyle
 * This is just a simple set of JQuery functions to get
 * some nice clean effects on my site, you're welcome to
 * use them if you like...
 */
$(document).ready(function(){ 

	//change home nav item to work
	if ($(".menu").length > 0) {
		$(".menu li:first-child a").html("About Us");
		$(".menu li:first-child").addClass("aboutUs");
		$(".menu li a").removeAttr("title");
	}
	
	//portia
	if ($("ul.post-meta").length > 0) {
		$("#mainCol ul.post-meta").hide();
	}
	$("#portia").toggle(function(){
		$("#mainCol ul.post-meta:first").show();
		$("#portia").addClass("portia2");
	},
	function(){
		$("#mainCol ul.post-meta").hide();
		$("#portia").removeClass("portia2");
	})
	
	/*if ($("#mainCol ul.post-meta li:empty")) {
		$("#mainCol ul.post-meta").css("left", "-1000px");
	}*/


	//Blog post rollover display info effect
	//First hide all
	if ($(".blogPreviewText").length > 0) {
		$(".blogPreviewText").hide();
	}
	function showPreview(){
		$(".blogPreviewText", this).fadeIn(500);
	};
	function hidePreview(){
		$(".blogPreviewText", this).fadeOut('slow');
	};
	//then toggle on hover
	$(".blogPostPreview").hoverIntent( showPreview, hidePreview )
	
	/*
	 * Old method, using regular hover, too frantic, using hoverIntent now
	 * 
	 * $(".blogPostPreview").hover(function(){
		$(".blogPreviewText", this).fadeIn(500);
		return false;
	},
	function(){
		$(".blogPreviewText", this).fadeOut('slow');
		return false;
	})*/
	
	
	
	
	//push initial position of the footer down after testing it exists
	if ($("#footer").length > 0) {
		$("#footer").css("bottom","-180px");
	}
	//controls are seperated into ie and non ie in footerToggle$.js



	//push initial position of the footer down after testing it exists
	if ($("#social").length > 0) {
		$("#social").css("top","-244px");
	}
	//controls are seperated into ie and non ie in footerToggle$.js
	
	
	
	//safari fixes
	isSafari3 = false;
	if(window.devicePixelRatio) isSafari3 = true;
	
	function loadjscssfile(filename, filetype){
		if (filetype=="js"){ //if filename is a external JavaScript file
			var fileref=document.createElement('script')
			fileref.setAttribute("type","text/javascript")
			fileref.setAttribute("src", filename)
		}
		else if (filetype=="css"){ //if filename is an external CSS file
			var fileref=document.createElement("link")
			fileref.setAttribute("rel", "stylesheet")
			fileref.setAttribute("type", "text/css")
			fileref.setAttribute("href", filename)
		}
			if (typeof fileref!="undefined")
			document.getElementsByTagName("head")[0].appendChild(fileref)
		}
		
	if (isSafari3 == true) {
		loadjscssfile("http://www.creativefreestyle.com/wp-content/themes/creativefreestyle2010/css/safari.css", "css") ////dynamically load and add this .css file
	}
	
	
	
	
	
	
	
	if(navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	{
	
		$(".blogPreviewText").show();
		loadjscssfile("http://www.creativefreestyle.com/wp-content/themes/creativefreestyle2010/css/iphone.css", "css") ////dynamically load and add this .css file
	};
	
	if(navigator.platform == 'iPad')
	{
	
		
		// Change wrapper height based on device orientation. Not strictly needed by iScroll, you may also use pure CSS techniques.
		function setHeight() {
			var wrapperH = window.innerHeight;
			document.getElementById('uberContainer').style.height = wrapperH + 'px';
		}
		// Check screen size on orientation change
		window.addEventListener('onorientationchange' in window ? 'orientationchange' : 'resize', setHeight, false);
		
	
		//This sets the scroll for iPad/iPhone to keep the screen ratio the same, and not move header/footer elements
		var myScroll;
		function loaded() {
			setHeight();	// Set the wrapper height. Not strictly needed, see setHeight() function below.
		
			// Please note that the following is the only line needed by iScroll to work. Everything else here is to make this demo fancier.
			myScroll = new iScroll('mainCol', {scrollbarColor: '#d7dd5f'});
		}
	
		$(".blogPreviewText").show();
		loaded();
		loadjscssfile("http://www.creativefreestyle.com/wp-content/themes/creativefreestyle2010/css/ipad.css", "css") ////dynamically load and add this .css file
		document.addEventListener('touchmove', function(e){ e.preventDefault(); }, false);
		

	};
	
	
	
	//BETA
	if ($("#beta").length > 0) {
		$("#betaPopup").hide();
	}
	
	$("#beta").hover(function(){
		$("#betaPopup", this).fadeIn(500);
		
	},
	function(){
		$("#betaPopup", this).fadeOut('slow');
	})
	
	
	
	
	


	
	
	
	
	
	
	
	
});
