$(document).ready(function() {
	
	$(".vidClip").hover(
	 function() { $(".vidClip p").css("background-color","#FF6600"); $(".vidClip p").css("color","#FFF");},
	 function() { $(".vidClip p").css("background-color","#C5C7CF"); $(".vidClip p").css("color","#666");
	});
	
	$(".vidClip2").hover(
	 function() { $(".vidClip2 p").css("background-color","#FF6600"); $(".vidClip2 p").css("color","#FFF");},
	 function() { $(".vidClip2 p").css("background-color","#C5C7CF"); $(".vidClip2 p").css("color","#666");
	});
	
	$(".promoClip").hover(
	 function() { $(".promoClip p").css("background-color","#FF6600"); $(".promoClip p").css("color","#FFF");},
	 function() { $(".promoClip p").css("background-color","#C5C7CF"); $(".promoClip p").css("color","#666");
	});
	    
	var hash = window.location.hash.substr(1);
	var href = $('#nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content';
			$('#content').load(toLoad)
		}											
	});

	$('#nav li a').click(function(){
								 
		var toLoad = $(this).attr('href')+' #content';
		var toLoadPg = $(this).attr('href')
		
		$('#content').hide('fast',loadContent);
		$('#load').remove();
		$('#wrapper').append('<span id="load">LOADING...</span>');
		$('#load').fadeIn('normal');
		
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		
		function loadContent() { $('#content').load(toLoad,'',showNewContent()) }
		function showNewContent() { $('#content').show('normal',hideLoader()); }
		function hideLoader() { $('#load').fadeOut('normal'); }

		return false;
	});
	
	
	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
	
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ left: -image_reelPosition }, 800 );
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 1000000); //Timer speed in milliseconds (3 seconds)
	};
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() { 
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
	
	var LeaderCount = 0;
	var jz = 0;
	var pk = 0;
	$('.leadershipImg').click(function(){
			if (  $(this).attr("src" ) == "imgs/john2.png" ){
				if(jz < 7){
					jz = jz + 1;
					LeaderCount = LeaderCount + 1;
				}else{
					LeaderCount = 0;
					jz = 0;
				}
			}
			if (  $(this).attr("src" ) == "imgs/patrick2.jpg" ){
				if(pk < 7){
					pk = pk + 1;
					LeaderCount = LeaderCount + 1;
				}else{
					pk = 0;
					LeaderCount = 0;
				}
			}
		
		if(LeaderCount > 13){
			LeaderCount = 0; 
			$("#bioCnt").html("<div id='contentThatFades'><div id='leadershipCont' class='clearfix f-right' style='clear: both;'><img src='imgs/richard.jpg' alt='Richard Alvarez' class='stage leadershipImg' /><div class='f-right'><h1 class='mainHead full'>Richard Alvarez</h1> <a href='http://www.linkedin.com/in/riquis' target='_blank' class='linkedInIcon' ></a><h2 class='subHead full'>Technology Director</h2><p>Richard began his career with Microsoft in Redmond, Washington. His emphasis is in visualizing content in a clear and simple manner. With nearly 25 years of experience in developing multimedia training, sales and marketing projects, he serves as a technologist and evangelist for design and development through new media. Prior to joining Method Engine, Richard ran his own interactive studio, SurpriseMedia. He is the author of Generator/Flash Web Development. (ISBN: 0735710805, New Riders Publishing). </p></div></div><div id='leadershipCont' class='clearfix f-left'> <img src='imgs/matt.jpg' alt='Matt Mefford' class='stage leadershipImg' /> <div class='f-right'> <h1 class='mainHead full'>Matt Mefford</h1> <h2 class='subHead full'>Creative Director</h2> <p>Matt is responsible for the visual development of the interactive experience (UI), IA, and managing/developing client's brand. Matt is an award-winning designer with a BS in graphic design. Prior to joining Method Engine in 2006, Matt designed for a variety of industries, including clients such as Edward hospital, AOA, AHA, Remedy, Argonne National Laboratories, the Chicago Park District, Chicago Public Library, the University of Chicago, and children's book publisher, Rigby Publishing.</p></div></div><div id='leadershipCont' class='clearfix f-left'> <img src='imgs/dages.jpg' alt='Matt Mefford' class='stage leadershipImg' /><div class='f-left'> <h1 class='mainHead full'>Pat Dages</h1> <h2 class='subHead full'>Office Manager</h2> <p>Pat Dages has played a variety of roles in the grand drama that has been his working career, most recently performing as the Operations Manager with the Method Engine Players. He is best known for short soliloquies that usually end with a curt, &quot;We're not paying for this.&quot; He has previously appeared as a newswire and newspaper reporter, lawyer, housepainter, and factory worker. Pat, a licensed attorney, has  B.A. in English and a J.D. from Loyola University.</p></div></div>");
			
			
			
		}
		Cufon.replace('.mainHead');
		Cufon.replace('.subHead');
		$("#bioCnt").slideDown(600, function(){
            $("#contentThatFades").fadeIn();
        });
	});
	
});


function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function quoteBoxOver(id){
	$("#"+id).stop().animate( { marginRight: "-5px" }, 100 );
	

	$("#"+id + " div").removeClass('gryarea');         
	$("#"+id + " div").attr('class','orgarea'); 

}
function quoteBoxOut(id){
	$("#"+id).stop().animate({ marginRight: "0px" }, 100 );

	//$("#"+id + " div").css("margin-right","-1px");

	$("#"+id + " div").removeClass('orgarea');         
	$("#"+id + " div").attr('class','gryarea'); 
}

function mycarousel_initCallback(carousel) {
	  jQuery('.jcarousel-control li a').bind('click', function() { 
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('rel'))); 
		updateSelected();
		jQuery(this).addClass('selected');
		
		Cufon.replace('#tabs li a' );
		
		return false; 
	  });
};
	
function updateSelected(){
	  jQuery('.jcarousel-control li a').removeClass('selected');
	  
	  Cufon.replace('#tabs li a' );
}


/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 254 2010-07-23 05:14:44Z emartin24 $
 */

jQuery(function ($) {
	// Load dialog on page load
	//$('#basic-modal-content').modal();

	// Load dialog on click
	$('#basic-modal .basic').click(function (e) {
		$('#basic-modal-content').modal();
		return false;
	});
	$('#basic-modal .basic2').click(function (e) {
		$('#basic-modal-content2').modal();
		return false;
	});
});
