/*
 * jQuery confession handler plugin
 *
 *
 * Copyright (c) 2008 Tamas Cser Digismarttech.com
 * All Rights Reserved
 */

;(function($) {
		 var DSTWindows = new Array();
	
		function DSTWindow(name) {
			this.width;
			this.height;
		}
		//this is necessary so we can open and reopen ths same element without losing the orig measurements
		var DSTW = new DSTWindow('adl');
		var DSTW2 = new DSTWindow('vid');
		var DSTW3 = new DSTWindow('cw');
		var DSTW4 = new DSTWindow('vi');
		
		$.openDSTWindow = function(e,speed,targete) {
		 	if (!speed) speed = 300;
			var c = $(e);
			
			if (e == '#pop-window') {		
				if (DSTW2.width == null || DSTW2.width == 'undefined') {		
					DSTW2.width = c.width();
					DSTW2.height = c.height();
				} 
				var width = DSTW2.width;
				var height = DSTW2.height;
			} else {
				if (DSTW.width == null || DSTW.width == 'undefined') {		
					DSTW.width = c.width();
					DSTW.height = c.height();
				} 
				var width = DSTW.width;
				var height = DSTW.height;				
			}
			
			
			var sch = $(window).height(); 
			var scw = $(window).width(); 

			var targetx = (scw - width) / 2;
			var targety = (sch - height) / 2 + $(window).scrollTop();

			if (targete != null) {
				var position = $(targete).offset();	
				targetx = position.left;// - (width / 2) + ($(targete).width() /2);
				targety = position.top + $(targete).height();
			} 
			//alert(targetx + " and " + targety + " and " + w + "  " + h + " AND " + scw + "  " + sch);		

			c.css('width','0');
		 	c.css('height','0');
			c.css('top','0');
		 	c.css('left','0');	 	
			c.css('display', 'block');
			c.animate({width:  width + "px",
			          opacity: 0.9,
					  top: targety + "px",
					  left: targetx + "px",
        			  height:  height + "px" 
        			      }, speed );
		}
			
		$.closeDSTWindow = function(e,speed) {
			var c = $(e);
			c.css('width','0');
		 	c.css('height','0');
			c.css('top','0');
		 	c.css('left','0');	 	
			c.css('display', 'none');			
			return;
			if (!speed) speed = 300;
			var c = $(e);
			c.animate({width: "0px",
				       opacity: 0.0,
					   top: "0px",
				 	   left: "0px",
        		  	   height: "0px"}, speed );			  
			
		}			
 
 $.processGuestbook = function(response) {
		$("#guestbookContainer").slideUp();
		$("#guestbookContainer").hide();
		if (response == 0) {
			var html = '<p>Sorry but your message could not be sent at this time.  Please try again later!</p>';
		} else {
			var html = '<p>Your message has been successfully sent!</p>';
		}
		$("#guestbookResponse").html(html);
		$("#guestbookResponse").show();
		$("#guestbookResponse").slideDown();
  }
  
  
})(jQuery);

