/*

	Jason Madeja website
	GUI Management JS
	by Rodger D. Kurth
	www.ChicagoWebDesignCo.com

*/

$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}

//var myScroll;

function loaded() {
	document.addEventListener('touchmove', function(e){ e.preventDefault(); });
	myScroll = new iScroll('mainContent');
}
document.addEventListener('DOMContentLoaded', loaded, false);

var msgs = ["<img src=\"images/banners/Construction-Help.jpg\" width=\"1020\" height=\"160\" />","<img src=\"images/banners/Jim.jpg\" width=\"1020\" height=\"160\" />","<img src=\"images/banners/Joyce-Car.jpg\" width=\"1020\" height=\"160\" />","<img src=\"images/banners/Kendra-Kongs.jpg\" width=\"1020\" height=\"160\" />","<img src=\"images/banners/Kongs-Phone.jpg\" width=\"1020\" height=\"160\" />","<img src=\"images/banners/Master-Plan.jpg\" width=\"1020\" height=\"160\" />","<img src=\"images/banners/Construction-Crane-CC.jpg\" width=\"1020\" height=\"160\" />"];
var i = 0; //counter of the items in the msgs array

function showMsgs(){
		
	/*  showMsgs()
		
	A simple jQuery animation coded by Rodger D. Kurth
	ChicagoWebDesignCo.com
	
	Dependencies:
	jQuery 1.3.2+ (not tested on earlier versions)
	
*/
$('#sub-heading').fadeTo(2400, 0,function(){
		$('#sub-heading').children().remove();
$(msgs[i]).prependTo('#sub-heading');								   
						});	   

$('#sub-heading').fadeTo(2400, 1.0);

i++;
	
	if (i>(msgs.length-1)){  /*this measures the number of text bits in the msgs array. Did it this way to allow user
	to enter as many messages as they want and not have to edit any other variables */
		i=0;
			}
		
	   }



$(document).ready(function(){
	var $box = $('.wrap');					   
	Cufon.replace('#heading h1',{fontFamily : 'trajan'});
	Cufon.replace('#heading h2',{fontFamily : 'trajan'});
	$(".leftBox a").colorbox({ transition:"elastic",speed:1200 });					   
	$(".rightBox a").colorbox({ transition:"elastic",speed:1200 });
	$(".midBox a").colorbox({ transition:"elastic",speed:1200 });
	//$(['../css/banner.jpg','../css/banner3.jpg','../css/banner2.jpg']).preload();	
	msgs_interval = setInterval(showMsgs,10000);
	
	$('nav a').click(function(event){
				event.preventDefault();
				//alert('Click function works');
				var $pageContent = 0;
				var $newContent;
				 $newURI = $(this).attr("href");
				 $.get($newURI,function(data){
					$newContent = data;
					$newContent = $($newContent).find(".wrap").html();
					},'html');
				$box.fadeTo(800,0,function(){
					$box.children().remove();
					$box.html($newContent);
					$(".leftBox a").colorbox({ transition:"elastic",speed:1200 });				   
					$(".rightBox a").colorbox({ transition:"elastic",speed:1200 });
					$(".midBox a").colorbox({ transition:"elastic",speed:1200 });
					$("#mainContent").scrollTop(0);
					});
				
				$box.fadeTo(800,1.0);							
				
		 }); //end ajax functions
	
						   
});
