//**************************
//*       Site v1.0       
//*      Authored by      
//* CreativeFreestyle.com 
//**************************

$(document).ready(function(){ 

	//***********************************
	// ADD A CLASS TO THE BODY IF JS ENABLED
	//***********************************
	$("body").addClass("jsEnabled");
	
	//***********************************
	// Clear/replace value
	//***********************************
	var searchBoxClearMePrevious = '';
	$("input.searchQ").focus(function(){
		if ( $(this).val() == $(this).attr('title') ) {
			searchBoxClearMePrevious = $(this).val();
			$(this).val('');
		}
	});
	$("input.searchQ").blur(function(){
		if ( $(this).val() == '' ) {
			$(this).val(searchBoxClearMePrevious);
		}
	});
	
	//***********************************
	// adding active class to hovered link
	//***********************************
	$("ul#menu-main > li").hover(function(){
		$(this).addClass("active");
	}, function(){
		$(this).removeClass("active");
	});
	
	//***********************************
	// adding parent links to nav
	//***********************************
	$("nav li").each(function(){
		if($("ul.sub-menu", this).length > 0) {
			$(this).addClass("parent");
		}
	})
	
	//***********************************
	// Remove alt tags on bg images
	//***********************************
	if($("#background").length > 0) {
		$("#background img").removeAttr("alt").removeAttr("title");
	}
	
	//***********************************
	// Device detection
	//***********************************
	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(navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
		loadjscssfile("http://martingoddarddesign.com/css/iphone2.css", "css") ////dynamically load and add this .css file
		
		$("footer span").append("<br >");
		
		addEventListener("load", function() {
                setTimeout(hideURLbar, 0);
        }, false);
        function hideURLbar() {
	        if (window.pageYOffset < 1) {
				window.scrollTo(0, 1);
			}
		}	
		
	};
*/
		
		
	
	if(navigator.platform == 'iPad'){
		
		loadjscssfile("http://jivamukti.creativefreestyle-dev.com/wp-content/themes/jiva/_assets/javascript/ipad.js", "js") ////dynamically load and add this .css file
	}
	
	//***********************************
	// external links new window
	//***********************************
	$("a[href^='http:']:not([href*='" + window.location.host + "'])").each(function() {               
		$(this).attr("target", "_blank");
	});
	
	//***********************************
	// print page
	//***********************************
	$(".pageTool1 a").click(function(e){
		e.preventDefault();
		window.print();
	})

	//***********************************
	// bookmark page
	//***********************************
	$(".pageTool3 a").click(function(e){
		e.preventDefault();
		if(document.all)window.external.AddFavorite(location.href,document.title);
		else if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');
	})
	
	
	/*----------------------------------------*/
	/* IE Fixes
	/*----------------------------------------*/
	if ($.browser.msie && $.browser.version.substr(0,1)<9) {
		
		//***********************************
		// Corners setup
		//***********************************
		
		// all corners - parent colour
		//$("aside.links li a").corner();
		
		// top corners - white
		//$("div.leftCol div#menu").corner("tl tr cc:#ffffff");
		
		// bottom corners - parent colour
		//$("div.leftCol div#menu").corner("bl br");
		
		// left corners
		//$("#cartPanel, #logInPanel").corner("tl bl");
		
		// top corners - dark green bg
		//$("#login a.button").corner("tl tr cc:#317d80");

		
	}
	
	
	
});
