document.createElement("header");
document.createElement("nav");
document.createElement("article");
document.createElement("aside");
document.createElement("section");
document.createElement("footer");

function RedirectIt() {
	location.replace('http://thepma.com/members-area/members-home/');
}

$(document).ready(function() {
	
	// Now found in header.php
	//$("#menu-primary-navigation li ul").append('<li class="menu-item menu-item-type-post_type"><a class="thickbox" href="#TB_inline?inlineId=addJob&amp;height=405&amp;width=600">Add a job</a></li>');
						   
	$("#contract-show-all").click(function() {
										   
		$("#contract-tools span").removeClass("selected-filter")
		$(this).addClass("selected-filter");
		
		$(".grouping").show();
		$(".grouping-part").show();
	});
	
	$("#contract-show-pma").click(function() {
		
		$("#contract-tools span").removeClass("selected-filter")
		$(this).addClass("selected-filter");
		
		$(".grouping").show();
		$(".grouping-part").hide();
		$(".grouping-part.PMA-Document").show();
		
		$(".grouping").each(function() {
			
			var grouping = $(this);

			if ( grouping.children(".grouping-part").is(":visible") == false) {
				$(this).hide();
			}
			
		});
		
	});
	
	$("#contract-show-industry").click(function() {
												
		$("#contract-tools span").removeClass("selected-filter")
		$(this).addClass("selected-filter");
		
		$(".grouping").show();
		$(".grouping-part").hide();
		$(".grouping-part.Industry-Contract").show();
		
		$(".grouping").each(function() {
			
			var grouping = $(this);

			if ( grouping.children(".grouping-part").is(":visible") == false) {
				$(this).hide();
			}
			
		});
		
	});

						   
	if ( $.cookie("user_email") != null && $.cookie("user_id") != null && $.cookie("user_login") != null ) {

		$("#DiscussionUser").val( $.cookie("user_id") );
		$("#DiscussionSender").val( $.cookie("user_email") );
		$("#DiscussionLogin").val( $.cookie("user_login") );

		$("#DiscussionUserJob").val( $.cookie("user_id") );
		$("#DiscussionSenderJob").val( $.cookie("user_email") );
		$("#DiscussionLoginJob").val( $.cookie("user_login") );

	}
						   
	$("#Form_PostComment").click(function() {
		
		var path = document.location.pathname;
		var pathID = path.split("/");

		$.ajax({
			type: "POST",
			url: "/wp-content/themes/pma/members-mail-notify.php",
			data: 	"DiscussionID=" + pathID[3] +
					"&DiscussionLogin=" + $.cookie("user_login"),
			success: function(){
				
				//alert("Email sent id " + pathID[3]);
				//setTimeout('RedirectIt()',3000);

			}
		});
							  
										  
		//alert(jQuery.url.attr("path"));
	});
						   
	$("#nav-main li a").addClass("thickbox");

	$("form#emailMemberForm").submit(function() {
		
		// Form handler not working Safari!?
		// alert("hello safari?!");				 

		var DiscussionUser			= $('#DiscussionUser').attr('value');
		var DiscussionName			= $('#DiscussionName').attr('value');
		var DiscussionCategoryID	= $('#DiscussionCategoryID').attr('value');
		var DiscussionBody			= $('#DiscussionBody').attr('value');
		var DiscussionSender		= $('#DiscussionSender').attr('value');
		var postToForum				= $('#postToForum').attr('value');
		var Submit					= $('#Submit').attr('value');
		
		if( $.trim(DiscussionName).length == 0 || $.trim(DiscussionBody).length == 0 || $.trim(DiscussionCategoryID).length == 0 ) { 
			
			//$('#emailMember').prepend('<div id="messages"><p><strong>All fields are required. Please try again.</strong></p></div>');
			$('#TB_ajaxContent').prepend('<div id="messages"><p><strong>All fields are required. Please try again.</strong></p></div>');
			
		} else { 
		
			$('#TB_ajaxContent #Submit').replaceWith('<p><strong>Sending. Please wait.</strong></p>');

			$.ajax({
				type: "POST",
				url: "/wp-content/themes/pma/members-mail-send.php",
				data: 	"DiscussionName=" + DiscussionName + 
						"&DiscussionCategoryID="+ DiscussionCategoryID + 
						"&DiscussionBody=" + DiscussionBody + 
						"&DiscussionSender=" + DiscussionSender + 
						"&Submit=" + Submit +
						"&DiscussionUser=" + DiscussionUser +
						"&postToForum="+ postToForum,
				success: function(){
					
					$('#TB_ajaxContent #emailMemberForm, #TB_ajaxContent #messages').hide();
					$('#TB_ajaxContent').prepend("<div id='messages'><p><strong>Your message has been successfully sent!</strong></p><p>You should be automatically redirected in just a moment. If you are not redirected, <a href='/members-area/members-home/'>click here</a>.</p></div>");

					setTimeout('RedirectIt()',3000);

				}
			});	
			
		}

		return false;

	});
	
	
	$("form#addJobForm").submit(function() {			 

		var DiscussionUser			= $('#DiscussionUserJob').attr('value');
		var DiscussionName			= $('#DiscussionNameJob').attr('value');
		var DiscussionCategoryID	= $('#DiscussionCategoryIDJob').attr('value');
		var DiscussionBody			= $('#DiscussionBodyJob').attr('value');
		var DiscussionSender		= $('#DiscussionSenderJob').attr('value');
		var postToForum				= $('#postToForumJob').attr('value');
		var Submitjob				= $('#SubmitJob').attr('value');
		
		if( $.trim(DiscussionName).length == 0 || $.trim(DiscussionBody).length == 0 || $.trim(DiscussionCategoryID).length == 0 ) { 
			
			$('#TB_ajaxContent').prepend('<div id="messages"><p><strong>All fields are required. Please try again.</strong></p></div>');
			
		} else { 
		
			$('#TB_ajaxContent #SubmitJob').replaceWith('<p><strong>Sending. Please wait.</strong></p>');

			$.ajax({
				type: "POST",
				url: "/wp-content/themes/pma/members-add-job.php",
				data: 	"DiscussionNameJob=" + DiscussionName + 
						"&DiscussionCategoryIDJob="+ DiscussionCategoryID + 
						"&DiscussionBodyJob=" + DiscussionBody + 
						"&DiscussionSenderJob=" + DiscussionSender + 
						"&SubmitJob=" + Submitjob +
						"&DiscussionUserJob=" + DiscussionUser,
				success: function(){
					
					$('#TB_ajaxContent #addJobForm, #TB_ajaxContent #messages').hide();
					$('#TB_ajaxContent').prepend("<div id='messages'><p><strong>Your job has been successfully add!</strong></p><p>You should be automatically redirected in just a moment. If you are not redirected, <a href='/members-area/members-home/'>click here</a>.</p></div>");

					setTimeout('RedirectIt()',3000);

				}
			});	
			
		}

		return false;

	});


	$("ul li:last-child, .vacancies .vacancy:last-child").addClass("last"); 
	$("#posts .item:first-child").addClass("first");
	// $("#panels .panel:nth-child(3n+3)").addClass("third");
	// $(".item:first").addClass("first");
	
	$(".fulldetail").hide();
	
	$("h3.title").click(function() {
		$(this).siblings(".fulldetail").slideToggle(500);
		//alert("hello");
	});
	
	$("#aa").click(function() {
		$("#DiscussionCategoryID option").removeAttr("selected");
		$("#DiscussionCategoryID option[value='3']").attr('selected', 'selected');
	});
	
	$("#da").click(function() {
		$("#DiscussionCategoryID option").removeAttr("selected");
		$("#DiscussionCategoryID option[value='2']").attr('selected', 'selected');
	});


	
	$('#slider') 
		.before('<div id="slideshowNav">') 
		.cycle({ 
			fx:     'fade', 
			speed:  500, 
			timeout: 7000, 
			pager:  '#slideshowNav' 
	});
		
	$('#sliderLong') 
		.before('<div id="slideshowNavLong">') 
		.cycle({ 
			fx:     'fade', 
			speed:  500, 
			timeout: 7000, 
			pager:  '#slideshowNavLong' 
	});

});
