// JavaScript Document

caSite = {
	contentLoad: function(url, type) {
		
		url = escape(url);
		
		if (type == 'ajax') {
			
			$('#caContentMain').fadeOut("fast");
			
			$('#caContentMain').load(escape(url), function(responseText, textStatus, XMLHttpRequest) { 
				if (XMLHttpRequest.status == '500' || XMLHttpRequest.status == '404') {
					$('#caContentMain').html(XMLHttpRequest.responseText);
				}
				$('#caContentMain').fadeIn("fast");
			} ); 
			
		} else {
			
			$('#caContentMain').fadeOut("fast", function() { $('#caContentMain').attr("src",url); });
			
		}
		
	},
	tabLoad: function(url, type) {
		
		url = escape(url);
		
		if (type == 'ajax') {
			
			$('#caPanes').fadeOut("fast");
			
			$('#caPanes').load(escape(url), function(responseText, textStatus, XMLHttpRequest) { 
				if (XMLHttpRequest.status == '500' || XMLHttpRequest.status == '404') {
					$('#caPanes').html(XMLHttpRequest.responseText);
				}
				$('#caPanes').fadeIn("fast");
			} ); 
			
		} else {
			
			$('#caPanes').fadeOut("fast", function() { $('#caPanes').attr("src",url); });
			
		}
		
	},
	windowLoad: function(url) {
		window.open(url);
	},
	dialogLoad: function(url, title, width, height, openCallback, closeCallback, overlayClose) {
		
		//url = escape(url);
		
		//Check for blank title- To overcome bug in colorbox that cashes previous if blank
		if (title == '' || !isNaN(title) ) {
			title = '&nbsp;';
		}
		
		// Add the padding for the interface frame
		if (!isNaN(width) && width > 1 ) {
			width = (width * 1);
			width = (width + 42);
		}
		if (!isNaN(height) && height > 1 ) {
			height = (height * 1);
			height = (height + 70);
		}

		// Check for blank height and width
		if (width == undefined || width == '') { width = '90%'; }
		if (height == undefined || height == '') { height = '90%'; }
		
		// Check for callbacks
		if (openCallback == undefined) { openCallback = false; }
		if (closeCallback == undefined) { closeCallback = false; }
		
		// Check for closeOnClickOut
		if (overlayClose == undefined) { overlayClose = true; }
		
		// Create colorbox to show dialog
		$.fn.colorbox.close();
		$.fn.colorbox({
			href: url, 
			open: true, 
			iframe: true, 
			title: title, 
			height: height, 
			width: width,
			onOpen: openCallback,
			onClose: closeCallback,
			overlayClose: overlayClose
		});
	},
	dialogClose: function(url) {
		$.fn.colorbox.close();
	},
	imageLoad: function(url, title, rel) {	
		//url = escape(url);
		$.fn.colorbox.close();
		$.fn.colorbox({href:url, open:true, photo:true, title:title}); 
	},
	videoLoad: function(url, title, rel) {	
		//url = escape(url);
		$.fn.colorbox.close();
		$.fn.colorbox({href:url, open:true, title:title}); 
	},
	alertLoad: function(title, text, sticky, life) {
		if(typeof(text) == "undefined") { 
			text = '';
		}
		if(typeof(sticky) == "undefined") { 
			sticky = false;
		}
		if(typeof(life) == "undefined") { 
			life = 4500;
		}
		
		$.jGrowl(text, { 
			header: title,
			theme: 'iphone',
			sticky: sticky,
			position: 'center',
			life: life
		});
	},
	functionLoad: function(url, params, method) {
		$.ajax({  type: method, url: url, data: params });
	}
};
