 
$(function(){

   /*--------------- Media Hub tabs  ---------------------------*/
   
	$('#contentHub .mediaArea:eq(0)').show(); //show mediaArea after it has initially been hidden
	
    $('.mediaTabs li').click(function() { 
		$('.mediaTabs li').removeClass('selected') //remove all classes 'selected' with mediaTabs list
		$(this).addClass('selected'); //add class 'selected' to this element
    });
	
	$('.mediaTabs #videoImage .tab1').click(function () {
	   $('.mediaArea').hide(); //hide all mediaArea's
	   $('.mediaArea:eq(0)').show(); //show first mediaArea
	});
	
	$('.mediaTabs #videoImage .tab2').click(function () {
	   $('.mediaArea').hide(); //hide all mediaArea's
	   $('.mediaArea:eq(1)').show(); //show second mediaArea
	});

	$('.close').click(function() {
	   $(this).parent().hide(); //close the Q&A text
	});
	
	$('.qa').click(function() {
		$(this).parent() //locate Q&A links parent
		.find('p.clearfix') //find the Q&A text
		.addClass('show') //add class 'show' to reveal element
		.toggle(); //toggle element to hide
	});
   
   /*--------------- Media Hub Video Gallery  ---------------------------*/
     
	 $('#watch .mediaList a').click(function(event, index){
		 event.preventDefault(); // stop page following link
		 $('#video').flash({
					swf:'/flash/player_autoplay.swf',
					height:304,
					width:380,
					flashvars: {  
						source: this.rel  
				    }
		 }); // jquery swfobject call
		 $('#videoTitle').html('');
		 $('#videoTitle').text(this.title);
		 
		
		 if(jQuery.url.setUrl(this.href).attr("path").length>1){
		 	$('#home #watch a.more').show();
		 	$('#home #watch a.more').attr('href',this.href);
		 }else{
		 	
		 	$('#home #watch a.more').hide();
		 	
		 }
		 
     });
	 
	 $('#watch .contentHub-browse a').click(function(event){
		 event.preventDefault(); // stop page following link
		 $('#video').flash({
					swf:'/flash/player_autoplay.swf',
					height:304,
					width:380,
					flashvars: {  
						source: this.href  
				    }
		 }); // jquery swfobject call
     });
	 
    /*--------------- Media Hub Read / Image Gallery  ---------------------------*/
   
   $('.readArticle:eq(0)').show(); //show readArticle after it has initially been hidden	
	
   $('#read li').each( // For each li, runcode. The index is the loop iteration index on the current element.
			    function(index){ // iteration index value.
				  $(this).click(function(){ 
					  $('.readArticle').hide();//hide all readArticles
					  $('.readArticle:eq('+index+')').show(); //show all selected Articles
				  }
				);
	});
   
     $('.contentHub-image:eq(0)').show(); //show contentHub image after it has initially been hidden	  
   
     $('#read .contentHub-browse a').each( // For each li, runcode. The index is the loop iteration index on the current element.
			    function(index){ // iteration index value.
				  $(this).click(function(event){  
 					  event.preventDefault(); // stop page following link		
					  $('.contentHub-image').hide();//hide all readArticles
					  $('.contentHub-image:eq('+index+')').show(); //show all selected Articles
				  }
				);
	});
    
	if ($('#contentHub #video').length > 0 ) {
    
	    var videoLink = $('.contentHub-browse a').attr('href'); 
		
		$('#video').flash({ //load first flash movie into media hub
			swf:'/flash/player.swf',
			height:304,
			width:380,
			flashvars: {  
				source: videoLink  
			}
		});
   
    }
	
}); //End jquery load function


//http://projects.allmarkedup.com/jquery_url_parser/index.php - added by AD 2009-03-17
jQuery.url=function(){var segments={};var parsed={};var options={url:window.location,strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};var parseUri=function(){str=decodeURI(options.url);var m=options.parser[options.strictMode?"strict":"loose"].exec(str);var uri={};var i=14;while(i--){uri[options.key[i]]=m[i]||""}uri[options.q.name]={};uri[options.key[12]].replace(options.q.parser,function($0,$1,$2){if($1){uri[options.q.name][$1]=$2}});return uri};var key=function(key){if(!parsed.length){setUp()}if(key=="base"){if(parsed.port!==null&&parsed.port!==""){return parsed.protocol+"://"+parsed.host+":"+parsed.port+"/"}else{return parsed.protocol+"://"+parsed.host+"/"}}return(parsed[key]==="")?null:parsed[key]};var param=function(item){if(!parsed.length){setUp()}return(parsed.queryKey[item]===null)?null:parsed.queryKey[item]};var setUp=function(){parsed=parseUri();getSegments()};var getSegments=function(){var p=parsed.path;segments=[];segments=parsed.path.length==1?{}:(p.charAt(p.length-1)=="/"?p.substring(1,p.length-1):path=p.substring(1)).split("/")};return{setMode:function(mode){strictMode=mode=="strict"?true:false;return this},setUrl:function(newUri){options.url=newUri===undefined?window.location:newUri;setUp();return this},segment:function(pos){if(!parsed.length){setUp()}if(pos===undefined){return segments.length}return(segments[pos]===""||segments[pos]===undefined)?null:segments[pos]},attr:key,param:param}}();



/* $('#read li').each( // For each li, runcode. The index is the loop iteration index on the current element.
	  function(index){// iteration index value.
	  $(this).bind (
	  "click",
		  function(){
			  $('.readArticle').hide();//hide all readArticles
			  $('.readArticle:eq('+index+')').show(); //show all selectedArticles
		  }
	    );
	  }
  );


     var videoPath = $('#watch .contentHub-browse a').attr('href'); //find first flash movie href   
	 
	 $('#video').flash({ //load first flash movie into media hub
					swf:'/flash/player.swf',
					height:304,
					width:380,
					flashvars: {  
						source: videoPath  
				    }
	  });
	 
	
	var videoHomePath = $('#watch .mediaList a').attr('href'); //find first flash movie href
	console.log(videoPath);
	
	 $('#home #video').flash({ //load first flash movie into media hub
					swf:'/flash/player.swf',
					height:304,
					width:380,
					flashvars: {  
						source: videoHomePath  
				    }
	  });

*/