// mYm Functions v 1.2 - brent@mimoymima.com
// last edited: July 5, 2009

// Document Ready Function
$(document).ready(function() {

	//-----LOAD PLUGINS
		
//	//-----ajaxify -- http://max.jsrhost.com/ajaxify/
//	/*
//	 * Ajaxify - jQuery Plugin
//	 * version: 2.00 (11/12/2008)
//	 * Created by: MaX
//	 * Examples and documentation at: http://max.jsrhost.com/ajaxify/
//	 * licensed under and GPL licenses:
//	 * http://www.gnu.org/licenses/gpl.html
//	 */
//	(function($){jQuery.AjaxifyDefaults={event:'click',link:false,target:'#container',animateOut:false,animateIn:false,animateOutSpeed:'normal',animateInSpeed:'normal',method:'GET',tagToload:false,loading_txt:'',loading_img:"images/loading.gif",loading_target:false,loading_fn:function(options){jQuery.ajaxifyLoading(options);},loadHash:false,title:false,forms:false,params:'ajax=true',timeout:false,contentType:"application/x-www-form-urlencoded",dataType:'html',cache:false,username:false,password:false,onStart:function(op){},onError:function(op){jQuery.ajaxifyManip(op,"<font style='color: #CC0000'>Error: </font> Couldn't open the page.");},onSuccess:function(op){},onComplete:function(op){}};jQuery.AjaxifyFirstLoad=true;jQuery.AjaxifyhistorySet=new Object();jQuery.AjaxifyPageTitle=document.title;jQuery.AjaxifyDebug=false;jQuery.fn.ajaxify=function(options){if(!jQuery(this).size()){jQuery.ajaxifylog('Error: No matched element/s for your ajaxify selector " '+jQuery(this).selector+' ".');return false;}
//	var ver=jQuery.fn.jquery.split('.');if(ver[0]<1||ver[1]<2||ver[2]<6){jQuery.ajaxifylog('Error: Your jQuery version is old. Version 1.2.6 or newer is required.');return false;}
//	return this.each(function(){var current=jQuery.extend({},jQuery.AjaxifyDefaults,options);if(jQuery.metadata){current=jQuery.extend(current,jQuery(this).metadata());}
//	if(current.event){jQuery(this).bind(current.event,function(){jQuery(this).ajaxifyAnalyse(current);if(!current.hash)
//	jQuery.ajaxifyLoad(current);else{jQuery.ajaxifyHash(current);}
//	if(jQuery(this).is('a')||jQuery(this).is('form'))return false;});}else{jQuery(this).ajaxifyAnalyse(current);jQuery.ajaxifyLoad(current);}
//	if(current.loadHash&&jQuery.AjaxifyFirstLoad){jQuery(this).ajaxifyAnalyse(current);if(document.location.hash.replace(/^#/,'')==current.hash&&current.hash){jQuery.ajaxifyHash(current);jQuery.AjaxifyFirstLoad=false;}}});};jQuery.fn.ajaxifyAnalyse=function(current){current.object=this;if(jQuery(this).is('a')){if(jQuery(this).attr('href')){var link=jQuery(this).attr('href').replace(/^#/,"");current.link=link||current.link;}else
//	current.link;if(typeof current.tagToload!='object')
//	if(jQuery(this).attr('target'))
//	current.target=jQuery(this).attr('target');else
//	current.target;else
//	current.target=current.loading_target||'#AjaxifyTemp';}
//	if(!current.loading_target)
//	current.loading_target=current.target;if(current.forms){var text=jQuery(current.forms).serialize();current.paramres=text;}
//	if(typeof current.params=='function')
//	var params=current.params(current);else
//	var params=current.params;if(typeof params=='string'){if(text)
//	current.paramres+='&'+params;else
//	current.paramres=params;}
//	var len=current.target.length-1;if(typeof current.tagToload!='object')
//	if(current.target.charAt(len)=='+'||current.target.charAt(len)=='-'){current.manip=current.target.charAt(len);current.target=current.target.substr(0,len);}
//	if(current.loadHash){if(!jQuery.historyInit){jQuery.ajaxifylog('Error: loadHash is enabled but history plugin couldn\'t be found.');return false;}
//	if(current.loadHash===true){jQuery.ajaxifylog('Info: It seemes you are upgrading from v1.0. Please see the new documentation about loadHash. "attr:href" will be used instead of "true".');current.loadHash="attr:href";}
//	if(current.loadHash.toLowerCase()=='attr:href'||current.loadHash.toLowerCase()=='attr:rel'||current.loadHash.toLowerCase()=='attr:title'){current.loadHash=current.loadHash.toLowerCase();current.hash=jQuery(this).attr(current.loadHash.replace('attr:',''));if(jQuery.browser.opera){current.hash=current.hash.replace('?','%3F');current.hash=current.hash.replace('&','%26');current.hash=current.hash.replace('=','%3D');}}else
//	current.hash=current.loadHash;if(!current.hash)
//	jQuery.ajaxifylog('Warning: You have specified loadHash, but its empty or attribute couldn\'t be found.');}
//	if(!jQuery(current.target).size()&&typeof current.tagToload!='object')
//	jQuery.ajaxifylog('Warning: Target " '+current.target+' " couldn\'t be found.');};jQuery.ajaxifyLoading=function(options){var html="<div id='AjaxifyLoading'><img src='"+options.loading_img+"' alt='Loading...' title='Loading...' >"+options.loading_txt+"</div>";if(options.loading_target)
//	jQuery.ajaxifyManip(options.loading_target,html);else
//	jQuery.ajaxifyManip(options,html);}
//	jQuery.ajaxifyHash=function(current){var ob=new Object();jQuery.each(current,function(key,value){ob[key]=value;});jQuery.AjaxifyhistorySet[ob.hash]=ob;location.hash=ob.hash;jQuery.historyInit(jQuery.ajaxifyHistory);jQuery.AjaxifyFirstLoad.history=false;};jQuery.ajaxifyLoad=function(current){jQuery.ajaxSetup({global:false});jQuery.ajax({type:current.method,url:current.link,dataType:current.dataType,data:current.paramres,contentType:current.contentType,processData:true,timeout:current.timeout,cache:current.cache,username:current.username,password:current.password,complete:function(){current.onComplete(current)},beforeSend:function(){current.onStart(current);if(current.animateOut){if(current.loading_target!=current.target);current.loading_fn(current);jQuery(current.target).animate(current.animateOut,current.animateOutSpeed,function(){if(!current.loading_target)
//	current.loading_fn(current);});}else
//	current.loading_fn(current);},success:function(data){jQuery(current.target).stop();jQuery('#AjaxifyLoading').remove();if(current.title)
//	document.title=current.title;else if(document.title!=jQuery.AjaxifyPageTitle)
//	document.title=jQuery.AjaxifyPageTitle;if(current.tagToload){data='<div>'+data+'</div>';if(typeof current.tagToload=='string'){jQuery.ajaxifyManip(current,jQuery(data).find(current.tagToload));}else if(typeof current.tagToload=='object'){jQuery.each(current.tagToload,function(tag,target){if(jQuery(data).find(tag).size())
//	jQuery.ajaxifyManip(target,jQuery(data).find(tag));else
//	jQuery.ajaxifylog('Warning: Tag "'+tag+'" couldn\'t be found.');});}}else{jQuery.ajaxifyManip(current,data);}
//	current.onSuccess(current,data);if(current.animateIn)
//	jQuery(current.target).animate(current.animateIn,current.animateInSpeed);},error:function(msg){jQuery(current.target).stop();current.onError(current,msg);if(current.animateIn)
//	jQuery(current.target).animate(current.animateIn,current.animateInSpeed);}});};jQuery.ajaxifylog=function(message){if(jQuery.AjaxifyDebug)
//	if(window.console){console.debug(message);}else{alert(message);}};jQuery.ajaxifyHistory=function(hash){if(hash){if(jQuery.browser.safari){var options=jQuery.AjaxifyhistorySet[location.hash.replace(/^#/,'')];}else
//	var options=jQuery.AjaxifyhistorySet[hash];if(options)
//	jQuery.ajaxifyLoad(options);else
//	jQuery.ajaxifylog('History Fired. But I couldn\'t find hash. Most propabley, the hash is empty. If so, its normal.');}};jQuery.ajaxifyManip=function(current,data){if(typeof current!='object'){var target=current;var current=new Object;var len=target.length-1;if(target.charAt(len)=='+'||target.charAt(len)=='-'){current.manip=target.charAt(len);current.target=target.substr(0,len);}
//	else{current.manip='';current.target=target;}
//	if(!jQuery(current.target).size())
//	jQuery.ajaxifylog('Warning: Target "'+current.target+'" couldn\'t be found.');}
//	if(current.manip=='+')
//	jQuery(current.target).append(data);else if(current.manip=='-')
//	jQuery(current.target).prepend(data);else
//	jQuery(current.target).html(data);};})(jQuery);
//
//	$('.ajaxify').ajaxify();


		
////	// - - - - - BEGIN: Ajax Video Switcher - - - - - - - - - - - - - - - - - - - -
//
//
//    // * * * * * *  SET THESE VARIABLES  * * * * * *
 
    // the trigger elements in the document (links or thumbnails or whatever)
    var Links = "#VideoThumbnails a.thumbnail";
 
    // The target element to replace with ajax
    var toReplace = "#VidContainer";
 
    // The replacement content Element
    var replacement = "#Video";
	
//    // * * * * * * * * * * * * * * * * * * * * * * * * * *
//
//    
    // when you click the thumbnail we're goign to load just the piece of the page that changes from another document
    $(Links).click(function(){
    
		// if there's already an active class set on something get rid of it
		$(Links).removeClass('Active');
		
		// adds the class of Active to whatever was clicked on so we can style it to have a downstate
		$(this).addClass('Active');	
//
//    	// This is a reference to the content we want to load $(this) is what was clicked
//    	var toLoad = $(this).attr('href')+' '+replacement;
//
//    	// Hides the div we're replacing and once that effect finished it then initiates the "loadContent" function
//    	$(toReplace).fadeOut('fast',loadContent);
//    
//    	// Removes Loading animation until it's needed -- not sure why this is here
//    	$('.Loading').remove();
//    
//    	// Put the Loading animation into the page, it's absolutely positioned in the css
//    	$('body').append('<span class="Loading">LOADING...</span>');
//    	
//    	// Fade in the Loading animation?  this part confuses me
//    	$('.Loading').fadeIn('normal');
//    
//    	// To allow someone to get a url for the state of the page we set the hash to be part of the href of the link clicked 
//		// YOU NEED TO CHANGE THE .substr numbers, the syntax is .substr(start,length) so the start part is after all the directories and the length should make it stop before .php or whatever file extension the url has
//    	window.location.hash = $(this).attr('href').substr(10,$(this).attr('href').length-14);    
//        
//    	// function to load the content
//    	function loadContent() {
//    		$(toReplace).load(toLoad,'',showNewContent());
//    	}
//    
//    	// function to show the new content
//    	function showNewContent() {
//    		$(toReplace).fadeIn('normal',hideLoader());
//    	}
//    
//    	// function that hides the preloader
//    	function hideLoader() {
//    		$('.Loading').fadeOut('normal');
//    	}
//
//    	// hijack the link's normal functionality (which would be to go to the normal HTML pages)
//    	return false;
//    	
    });
    

//	//BEGIN: ORIGINAL VERSION -- delete later?
//	var hash = window.location.hash.substr(1);
//	var href = $(Links).each(function(){
//		var href = $(this).attr('href');
//		if(hash==href.substr(0,href.length-4)){
//			var toLoad = hash+'.php '+toReplace;
//			$('#FlashDiv').load(toLoad)
//		}											
//	});
//
//	$(Links).click(function(){
//								  
//		var toLoad = $(this).attr('href')+' #FlashDiv';
//		$('#FlashDiv').fadeOut('fast',loadContent);
//		$('#load').remove();
//		$('body').append('<span id="load">LOADING...</span>');
//		$('#load').fadeIn('normal');
//    	window.location.hash = $(this).attr('href').substr(10,$(this).attr('href').length-14);    
//		function loadContent() {
//			$('#FlashDiv').load(toLoad,'',showNewContent());
//		}
//		function showNewContent() {
//			$('#FlashDiv').fadeIn('normal',hideLoader());
//		}
//		function hideLoader() {
//			$('#load').fadeOut('normal');
//		}
//		return false;
//		
//	});
//	
//	// END: ORIGINAL VERSION -- delete later?



//END: Document Ready Function	
});