jQuery.noConflict();


/**
   * PK Init Vars
*/

	var pk_stage_width = 0;
	var pk_stage_height = 0;
	var pk_content_height = 0;

	var pk_page_max_height = pk_page_box_max_height;


/*
  * Document / Window Events
*/

	jQuery(document).ready(function() {

		jQuery("body").removeClass("pk_standard_pages");
		jQuery("#wrapper").removeClass("pk_center_box").show();

		pk_stage_width = jQuery(window).width();
		pk_stage_height = jQuery(window).height();

		pkCreateMainMenu();
		pkCreateControls();
		pkCreateText();

	});

	jQuery(window).resize(function() {

		pk_stage_width = jQuery(window).width();
		pk_stage_height = jQuery(window).height();

		pkResizeMainMenu();
		pkResizeControls();
		pkResizeText();

	});


/**
   * PK Create Main Menu
*/

	function pkCreateMainMenu() {

		var menu = jQuery("nav");
		var logo = jQuery("header h1");
		var logo_top = (pk_stage_height <= 700) ? 40 : Math.round(pk_stage_height / 8);

		menu.hide();
		logo.hide();

		menu.css({ "position" : "absolute", "left" : Math.round((pk_stage_width / 2) - (menu.outerWidth() / 2)) + "px", "top" : 0 + "px"}).show();
		logo.css({ "position" : "absolute", "left" : "0px", "top" : logo_top + "px" }).show();

	}


/**
   * PK Resize Main Menu
*/

	function pkResizeMainMenu() {

		var menu = jQuery("nav");
		var logo = jQuery("header h1");
		var logo_top = (pk_stage_height <= 700) ? 40 : Math.round(pk_stage_height / 8);
	
		menu.css({ "left" : Math.round((pk_stage_width / 2) - (menu.outerWidth() / 2)) + "px", "top" : 0 + "px" });
		logo.css({ "position" : "absolute", "left" : "0px", "top" : logo_top + "px" }).show();
		
	}


/**
   * PK Create Controls
*/

	function pkCreateControls() {

		var footer = jQuery("footer");
		var controls = jQuery("#pk_controls");

		controls.css({ "width" : "auto", "visibility" : "hidden" });
		jQuery(".pk_footer_info", controls).css({ "display" : "inline" });
		footer.css({ "position" : "absolute", "top" : Math.round(pk_stage_height - 30) + "px" });
		
		setTimeout(function() {
			var controls_width = jQuery(".pk_footer_info", controls).width() + jQuery(".pk_footer_sn", controls).outerWidth() + 50;
			controls.css({ "position" : "absolute", "left" : Math.round((pk_stage_width / 2) - (controls_width / 2)) + "px", "width" : controls_width + "px", "visibility" : "visible" });
		}, 400);

	}


/**
   * PK Resize Controls
*/

	function pkResizeControls() {

		var footer = jQuery("footer");
		var controls = jQuery("#pk_controls");
		var controls_width = controls.width();

		controls.css({ "position" : "absolute", "left" : Math.round((pk_stage_width / 2) - (controls_width / 2)) + "px", "top" : 0 + "px" });
		footer.css({ "position" : "absolute", "top" : Math.round(pk_stage_height - 30) + "px" });

	}


/**
   * PK Create Text
*/

	function pkCreateText() {

		pkResizeObject("#pk_text");
		pkPositionObject("#pk_text");

		pk_content_height= jQuery("#pk_text_content").height();

		jQuery("#pk_text").addClass("pk_shadow");
		jQuery("#pk_text_wrapper").css({ "margin-top" : 40 + "px" , "height" : (jQuery("#pk_text").height() - 80) + "px" });

		var margin_top = Math.round((jQuery("#pk_text_wrapper").height() / 2) - (jQuery("#pk_text_content").height() / 2));

		if(jQuery("#pk_text_wrapper").height() <= pk_content_height) {

			jQuery("#pk_text_content").css({ "margin-top" : 0 + "px" });
			jQuery('#pk_text_entries').css({ "height" : jQuery("#pk_text_wrapper").height() + "px" });
			jQuery('#pk_text_entries').jScrollPane();

		} else {

			(margin_top <= 0) ? jQuery("#pk_text_content").css({ "margin-top" : 0 + "px" }) : jQuery("#pk_text_content").css({ "margin-top" : margin_top + "px" });

		}

		(jQuery("#pk_text_wrapper").height() > pk_content_height) ? jQuery("#pk_text_inner").css({ "width" : 720 + "px" }) : jQuery("#pk_text_inner").css({ "width" : 700 + "px" });

	}


/**
   * PK Resize Text
*/

	function pkResizeText() {
	
		pkResizeObject("#pk_text");
		pkPositionObject("#pk_text");

		jQuery("#pk_text_wrapper").css({ "height" : (jQuery("#pk_text").height() - 80) + "px" });

		var margin_top = Math.round((jQuery("#pk_text_wrapper").height() / 2) - (jQuery("#pk_text_content").height() / 2));

		if(jQuery("#pk_text_wrapper").height() <= pk_content_height) {

			jQuery("#pk_text_content").css({ "margin-top" : 0 + "px" });
			jQuery('#pk_text_entries').css({ "height" : jQuery("#pk_text_wrapper").height() + "px" });

		} else {

			(margin_top <= 0) ? jQuery("#pk_text_content").css({ "margin-top" : 0 + "px" }) : jQuery("#pk_text_content").css({ "margin-top" : margin_top + "px" });
			jQuery('#pk_text_entries').css({ "height" : pk_content_height + "px" });

		}

		(jQuery("#pk_text_wrapper").height() > pk_content_height) ? jQuery("#pk_text_inner").css({ "width" : 720 + "px" }) : jQuery("#pk_text_inner").css({ "width" : 700 + "px" });
		jQuery('#pk_text_entries').jScrollPane();
		
	}


/**
   * PK Resize Object
*/

	function pkResizeObject(object) {

		var obj = jQuery(object);

		var max_width = 910;
		var max_height = Math.round(jQuery(window).height() - 120);

		(max_height >= pk_page_max_height) ? obj.css({ "width" : max_width + "px", "height" : pk_page_max_height + "px" }) : obj.css({ "width" : max_width + "px", "height" : max_height + "px" });

	}


/**
   * PK Position Object
*/

	function pkPositionObject(object) {

		var obj = jQuery(object);

		var pk_stage_width = jQuery(window).width();
		var pk_stage_height = jQuery(window).height();

		obj.css({"position" : "absolute", "left" : (pk_stage_width / 2) - (obj.width() / 2), "top" : (pk_stage_height / 2) - (obj.height() / 2) });

	}
