/* ******************************************************************************************
 * Created by FireCoding
 * 7/31/11 5:34 PM
 * ******************************************************************************************/
var $$ = {};




$(document).ready(function() {





	// print page specific content
	switch (okeanos.page) {
		case 'blank':
			break;

	}


	okeanos.setup_bg = function()
	{
		// setup grunge bg to fullscreen
		resize_image_to_fill_container($('div#page_grunge_bg_cont'),$('img#page_grunge_bg_img'), 1920, 1276);
	};


	okeanos.init_page = function()
	{
		$$.winX = (document.all)?window.screenLeft:window.screenX;
		$$.winY = (document.all)?window.screenTop:window.screenY;

		okeanos.setup_bg();
		$('div#c1_contact_info '+'>'+' span').hide();
	};




	// init
	okeanos.init_page();


	// ========================================================================================================================

	okeanos.resizing = false;
	$(window).resize(function() {
		if ( ! okeanos.resizing) {

			// set concurrency flag to prevent multiple events firing at once
			okeanos.resizing = true;

			// reset concurrency flag
			setTimeout('okeanos.setup_bg(); okeanos.resizing = false;',100);
		}
	});
	
	function resize_image_to_fill_container($container, $image, width, height, offset_x_percent, offset_y_percent) {

		// setup default values for optional parameters
		offset_x_percent = (typeof offset_x_percent == 'undefined') ? 0 : offset_x_percent;
		offset_y_percent = (typeof offset_y_percent == 'undefined') ? 0 : offset_y_percent;

		// get dimensions
		var container_x = $container.width();
		var container_y = $container.height();

		// vars
		var new_width,new_height,new_x,new_y;
		var window_aspect_ratio = container_x / container_y;
		var image_aspect_ratio = width / height;

		// get new dimensions
		if (window_aspect_ratio <= image_aspect_ratio) {
			// get new image dimensions (use height, scale width)
			new_width = container_y * image_aspect_ratio;
			new_height = container_y;
		}
		else {
			// get new image dimensions (use width, scale height)
			new_width = container_x;
			new_height = container_x / image_aspect_ratio;
		}

		// center the image
		new_x = -(new_width-container_x)/2;
		new_y = -(new_height-container_y)/2;

		// offset the image
		new_x += container_x * offset_x_percent;
		new_y += container_y * offset_y_percent;

		// save settings
		$image.css({
			width : new_width,
			height : new_height,
			left : new_x,
			top : new_y
		});

	}

	function resize_image_to_fit_container($container, $image, width, height, offset_x_percent, offset_y_percent) {

		// setup default values for optional parameters
		offset_x_percent = (typeof offset_x_percent == 'undefined') ? 0 : offset_x_percent;
		offset_y_percent = (typeof offset_y_percent == 'undefined') ? 0 : offset_y_percent;

		// get dimensions
		var container_width = $container.width();
		var container_height = $container.height();


		// vars
		var new_width,new_height,new_x,new_y;
		var window_aspect_ratio = container_width / container_height;
		var image_aspect_ratio = width / height;

		// get new dimensions
		if (window_aspect_ratio <= image_aspect_ratio) {
			// get new image dimensions (use width, scale height)
			new_width = container_width;
			new_height = container_width / image_aspect_ratio;
		}
		else {
			// get new image dimensions (use height, scale width)
			new_width = container_height * image_aspect_ratio;
			new_height = container_height;
		}

		// center the image or offset the image
		if (offset_x_percent == 'auto') {
			new_x = -(new_width-container_width)/2;
		} else {
			new_x = container_width * offset_x_percent;
		}
		if (offset_y_percent == 'auto') {
			new_y = -(new_height-container_height)/2;
		} else {
			new_y = container_height * offset_y_percent;
		}

		if (offset_x_percent == 'right' && offset_y_percent == 'bottom') {
			// save settings
			$image.css({
				width : new_width,
				height : new_height,
				right : 0,
				bottom : 0
			});
		}
		else {
			// save settings
			$image.css({
				width : new_width,
				height : new_height,
				left : new_x,
				top : new_y
			});
		}



	}


});
