/*
*	mStudios Code Snippets
*	-----------------------
*
*	@file 		mstudios.js
*	@version 	1.0.0b
*	@date 		2011-06-08 (Wed, 8 June 2011)
*	@author 	Marlyse Comte <code@mStudios.com>
*
*	Copyright (c) 2011 mStudios <http://www.mStudios.com>
*/


// only run if the document has finished loading
$(document).ready(function() {


// hide the tooltips
//-----------------------------------------------------------

	var tip = '';
	var tipreplace = '';
	
	
	$('a').hover(function(event) {
		
		// hover mouse on
		tip = $(this).attr('title');
		tipreplace = tip;
		$(this).attr('title','');
		
	}, function() { 
		// hover mouse off	
		$(this).attr('title',tipreplace);
		
	});
	
	
	
// preload the CSS background-images
//------------------------------------------------------------
// 

	jQuery.preloadCssImages = function(){
	        var allImgs = [];//new array for all the image urls 
	        var k = 0; //iterator for adding images
	        var sheets = document.styleSheets;//array of stylesheets
	       
	        for(var i = 0; i<sheets .length; i++){//loop through each stylesheet
	                var cssPile = '';//create large string of all css rules in sheet
	                var csshref = (sheets[i].href) ? sheets[i].href : 'window.location.href';
	                var baseURLarr = csshref.split('/');//split href at / to make array
	                baseURLarr.pop();//remove file path from baseURL array
	                var baseURL = baseURLarr.join('/');//create base url for the images in this sheet (css file's dir)
	                if(baseURL!="") baseURL+='/'; //tack on a / if needed
	                if(document.styleSheets[i].cssRules){//w3
	                        var thisSheetRules = document.styleSheets[i].cssRules; //w3
	                        for(var j = 0; j<thisSheetRules.length; j++){
	                                cssPile+= thisSheetRules[j].cssText;
	                        }
	                }
	                else {
	                        cssPile+= document.styleSheets[i].cssText;
	                }
	               
	                //parse cssPile for image urls and load them into the DOM
	                var imgUrls = cssPile.match(/[^(]+.(gif|jpg|jpeg|png)/g);//reg ex to get a string of between a "(" and a ".filename"
	                if(imgUrls != null && imgUrls.length>0 && imgUrls != ''){//loop array
	                        var arr = jQuery.makeArray(imgUrls);//create array from regex obj       
	                        jQuery(arr).each(function(){
	                                allImgs[k] = new Image(); //new img obj
	                                allImgs[k].src = (this[0] == '/' || this.match('http://')) ? this : baseURL + this;     //set src either absolute or rel to css dir
	                                k++;
	                        });
	                }
	        }//loop
	        return allImgs;
	}
	
	jQuery.preloadCssImages();
	

// animate the hover popup images
//------------------------------------------------------------
// 
	
	var offsetX = 20;
	var offsetY = 10;
	
	$('#web-intro div.featured a').hover(function(event) {  // hover mouse on
		var href = $(this).attr('href');
		 $('<img id="largeImage" src="' + href + '" alt="large image" />')
		 	.css('top', event.pageY + offsetY)
		 	.css('left', event.pageX + offsetX)
		 	.appendTo('#web-intro');
		}, function(){ // hover mouse off
			$('#largeImage').remove();
	});
	
	$('#photography-intro div.featured a').hover(function(event) {  // hover mouse on
		var href = $(this).attr('href');
		 $('<img id="largeImage" src="' + href + '" alt="large image" />')
		 	.css('top', event.pageY + offsetY)
		 	.css('left', event.pageX + offsetX)
		 	.appendTo('#photography-intro');
		}, function(){ // hover mouse off
			$('#largeImage').remove();
	});
	
	$('#digital-intro div.featured a').hover(function(event) {  // hover mouse on
		var href = $(this).attr('href');
		 $('<img id="largeImage" src="' + href + '" alt="large image" />')
		 	.css('top', event.pageY + offsetY)
		 	.css('left', event.pageX + offsetX)
		 	.appendTo('#digital-intro');
		}, function(){ // hover mouse off
			$('#largeImage').remove();
	});

	
	$('.featured a').mousemove(function(event) {
			$('#largeImage').css('top', event.pageY + offsetY).css('left', event.pageX + offsetX);
		});
	
	$('.featured a').click(function(event) {
			return false;
		});


//animate to the different sections
//-----------------------------------------------------------

/*
//////-----------------------------------------------------------go-web  
	// when a#go2webT is clicked
		$('a#go2webT').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#web').animate({"top" : "-750px"}, 600);
		return false;
	}); 
	
	// when a#go2webP is clicked
		$('a#go2webP').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#web').animate({"top" : "-750px"}, 600);
		return false;
	}); 
//////-----------------------------------------------------------go-photography	 
	// when a#go2photoT is clicked
		$('a#go2photoT').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#photography').animate({"top" : "-1350px"}, 600);
		return false;
	}); 
	
	// when a#go2photoP is clicked
		$('a#go2photoP').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#photography').animate({"top" : "-1350px"}, 600);
		return false;
	}); 
//////-----------------------------------------------------------go-digital	 
	// when a#go2digiT is clicked
		$('a#go2digiT').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#digital').animate({"top" : "-1950px"}, 600);
		return false;
	}); 
	
	// when a#go2digiP is clicked
		$('a#go2digiP').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#digital').animate({"top" : "-1950px"}, 600);
		return false;
	}); 
//////-----------------------------------------------------------go-lounge	 
	// when a#go2loungeT is clicked
		$('a#go2loungeT').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#lounge').animate({"top" : "-2550px"}, 600);
		return false;
	}); 
	
	// when a#go2loungeP is clicked
		$('a#go2loungeP').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#lounge').animate({"top" : "-2550px"}, 600);
		return false;
	}); */ 
//////-----------------------------------------------------------go-utilities	
	// when a#go2utilitiesT is clicked
		$('a#go2utilitiesT').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#utilities').animate({"top" : "-3150px"}, 600);
		return false;
	}); 
	
	// when a#go2utilitiesP is clicked
		$('a#go2utilitiesP').click(function() {
		$('#home').animate({"top" : "-1900px"}, 600);
		$('#utilities').animate({"top" : "-3150px"}, 600);
		return false;
	});  
//////-----------------------------------------------------------go-home	
	// when a#goHome is clicked
		$('a.goHome').click(function() {
		$('#web').animate				({"top" : "750px"}, 600);
		$('#photography').animate		({"top" : "1350px"}, 600);
		$('#digital').animate			({"top" : "1950px"}, 600);
		$('#lounge').animate				({"top" : "2550px"}, 600);
		$('#utilities').animate			({"top" : "3150px"}, 600);
		$('#home').animate				({"top" : "0px"}, 600);
		return false;
	}); 



// end of the document ready function
});	

		
		
