$(document).ready(function(){

	//populate all the header titles properly
	$('.postText h4').each(function(){
		var postTitle = $(this).html();
		//alert(postTitle);
		//move to the top
		//$(this).parent('.postText').children('.postTitle').html(postTitle);
		$(this).parent('.postText').parent('.content').children('.postTitle').html(postTitle);
		$(this).remove();
		

	});
	/*if(!$.browser.msie){
		//replace all the smalls with largers
		$('.postText dt object').each(function(){
			
			//first change the game to the larger version
			//get the code
			var oldGame = $(this).parent().html();
			oldGame = oldGame.replace("500","640");
			oldGame = oldGame.replace("300","400");
			oldGame = oldGame.replace("_sm.swf",".swf");
			//oldGame = oldGame.replace("<object","<object style='display:block'");

			$(this).replaceWith(oldGame);
			//$(this).parent().css('display','block');
			//$(this).parent().show();
			//alert($(this).html());
			//$(this).parent().addClass('show');
			
		});
	}*/

	//check to see if this page has any flash SWFs to enable <embed> code
	var normal;
	var smaller;
	/*if($('.postText dt object').length > 0){
				
		//lets move this after the DT object
		if($('.embed').length > 0){ //if it exists then build and reposition
			var embedHTML = '<div class="embed">' + $('.embed').html() + '</div>';
			//alert(embedHTML);
			$('.embed').remove();
			//insert it after the object
			$('.postText dt').after(embedHTML);
			$('.embed').css("display", "block");
			var url = $('.postText dt object').attr('data');
			normal = url;
			//url = substring(0, url.indexOf("."));
			//url = url + "_sm.swf";
			//alert(url);
			url = url.replace(".swf", "_sm.swf");
			smaller = url;

			//insert this url into the embed code
			$('.embed .embedURL form input').attr("value", "<object width='500' height='300' type='application/x-shockwave-flash' data='" + url + "'><param value='true' name='allowFullScreen'/><param value='always' name='allowscriptaccess'/><param value='" + url + "' name='src'/><param value='true' name='allowfullscreen'/></object>");
		}
	}*/

	if($('.postText dt object').length > 0){
				
		//lets move this after the DT object
		if($('.embed').length > 0){ //if it exists then build and reposition
			var embedHTML = '<div class="embed">' + $('.embed').html() + '</div>';
			//alert(embedHTML);
			$('.embed').remove();
			//insert it after the object
			$('.postText dt').after(embedHTML);
			$('.embed').css("display", "block");
			var url = $('.postText dt object').attr('data');
			smaller = url;
			//url = substring(0, url.indexOf("."));
			//url = url + "_sm.swf";
			//alert(url);
			url = url.replace("_sm.swf", ".swf");
			normal = url;

			//insert this url into the embed code
			$('.embed .embedURL form input').attr("value", "<object width='500' height='400' type='application/x-shockwave-flash' data='" + smaller + "'><param value='true' name='allowFullScreen'/><param value='always' name='allowscriptaccess'/><param value='" + smaller + "' name='src'/><param value='true' name='allowfullscreen'/></object>");
		}
	}

	if($('.video dt object').length > 0){
				
		//lets move this after the DT object
		if($('.embed').length > 0){ //if it exists then build and reposition
			var embedHTML = '<div class="embed">' + $('.embed').html() + '</div>';
			//alert(embedHTML);
			$('.embed').remove();
			//insert it after the object
			$('.video dt').after(embedHTML);
			$('.embed').css("display", "block");
			var url = $('.video dt object').attr('data');
			smaller = url;
			//url = substring(0, url.indexOf("."));
			//url = url + "_sm.swf";
			//alert(url);
			url = url.replace("_sm.swf", ".swf");
			normal = url;

			//insert this url into the embed code
			$('.embed .embedURL form input').attr("value", "<object width='500' height='400' type='application/x-shockwave-flash' data='" + smaller + "'><param value='true' name='allowFullScreen'/><param value='always' name='allowscriptaccess'/><param value='" + smaller + "' name='src'/><param value='true' name='allowfullscreen'/></object>");
		}
	}

	$('.embedText select').change(function(){
		//get the url first
		var type = $('.embed .embedURL form input').attr("value");

		if($(this).val() == "Small"){
			//switch to smaller
			$('.embed .embedURL form input').attr("value", "<object width='500' height='400' type='application/x-shockwave-flash' data='" + smaller + "'><param value='true' name='allowFullScreen'/><param value='always' name='allowscriptaccess'/><param value='" + smaller + "' name='src'/><param value='true' name='allowfullscreen'/></object>");
		}
		else{
			$('.embed .embedURL form input').attr("value", "<object width='640' height='400' type='application/x-shockwave-flash' data='" + normal + "'><param value='true' name='allowFullScreen'/><param value='always' name='allowscriptaccess'/><param value='" + normal + "' name='src'/><param value='true' name='allowfullscreen'/></object>");
		}
	});
	
	$('a.navLink').click(function(){
		if($.browser.msie){
			var href = $(this).attr('href');
			//go to this page
			window.location = href;
		}
	});
	//need to do this for each
	
	//if($('.read_more_container').length > 0){
	$('.read_more_container').each(function () {
		var readMoreLink = $(this).html();
		//alert($(this).parent().html());
		
		var firstP;
		if($(this).parent().parent().attr("class") == "postText"){
			firstP = $(this).parent().parent().children('p:first').html();
			$(this).parent().parent().children('p:first').replaceWith("<p>" + firstP + " " +  readMoreLink + "</p>"); 
		}
		else if($(this).parent().attr("class") == "postText"){
			firstP = $(this).parent().children('p:first').html();
			$(this).parent().children('p:first').replaceWith("<p>" + firstP + " " +  readMoreLink + "</p>"); 
		}
		//alert(firstP);
		//alert($(this).parent().parent('.postText').html());
		//$(this).parent('.postText').children('p:first').replaceWith("<p>" + firstP + " " +  readMoreLink + "</p>"); 
		$(this).remove();
	  });
	//}

	/*if($('.read_more_container').length > 0){
		//move it to after the last thingy
		
		$('.read_more_container').remove();
		//put this link inside the first paragraph
		var firstP = $('.postText p:first').html();
		$('.postText p:first').replaceWith("<p>" + firstP + " " +  readMoreLink + "</p>");
	}*/
});
