/**
 * JavaScripts and jQuery
 *
 * @author          Emil Lansky <elansky@plus4inc.com>
 * @copyright       Plus Four Inc. 2008
 *
 * All Rights Reserved
 *
 * Distribution and use in source and binary forms, with or without
 * modification, are NOT permitted without prior written permition from the
 * authors and copyright holders
 *
**/

this.imagePreview = function(){	
//	CONFIG 
		xOffset = 10;
		yOffset = 30;
//	END CONFIG

	$("a.pop-preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },

	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	

	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

jQuery(document).ready(function() {

/*
  jQuery("a").hover(function(){
	jQuery(this).addClass("highlight");
  },function(){
	jQuery(this).removeClass("highlight");
  });

  jQuery("input[name='toggleSelectAllCheckbox']").click(function() {
	 jQuery("input[name*=sel]").each(function() {
		this.checked = !this.checked;
	 });
  });

  jQuery("input[name='msg_type']").click(function() {
	 var str = $("input[name='msg_type']:checked").val();
	 if ( str == "HTML") 
		jQuery("textarea").addClass("mceAdvanced");            
	 else
		jQuery("textarea").addClass("mceSimple");
  });

  jQuery("div#menu ul li").click(function() {
	 jQuery(this).addClass("active");
  },function(){
	 jQuery(this).removeClass("active");
  });
*/

  jQuery("#center-image").bind("load", function () {
	var screen_height =  Math.floor(screen.availHeight * 0.66);
	var screen_width =  Math.min(Math.floor(screen.availWidth * 0.6),Math.floor(parseInt($("#content").css("width")))*0.6);
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ver = navigator.appVersion;
		if (ver.substring(0,1) == '4') {
			screen_height =  Math.floor(screen.availHeight * 0.65);
			$("#main-content").css( { "height":screen_height } );
		}
	}
	var ratio = ($(this).height()/$(this).width()).toFixed(2);	//Image ratio
	if (ratio >= 0) { // lansdscape
		var this_width = Math.floor(screen_height/ratio);
		var this_height = Math.floor(this_width * ratio);
		if ((this_width+400)>screen_width) {
			screen_height = Math.floor(screen_height * (screen_width / (this_width+400) ));
		}
	  i_left =  Math.abs((screen_width - (screen_height/ratio))/2);
	  i_top	 =  Math.abs((screen_height - this_height)/2);
	} else { // portrait
	  i_left =  Math.abs((screen_width - (screen_height*ratio))/2);
	  i_top	 =  0;
	}
	var l_left = Math.floor((screen_width)/2);
	$(this).css( { "height":screen_height, "width":"auto","position":"absolute","top":i_top, "left":i_left, "z-index":2 } );
	$("#center-text").css( { "position":"fixed","left":l_left,"top":"45%","z-index":2,"font-size":"130%","color":"#FFF" } );
	$("#center-text").show();
	$(this).delay(900).fadeIn(10000);
  });

  jQuery('#website_hosted input').is(':checked') ? jQuery("div#set_website_hosted").show() : jQuery("div#set_website_hosted").hide();

  jQuery('#website_hosted input').click(function() {
	if (this.checked) {
	  jQuery("#set_website_hosted").show();
	  if (jQuery('#web_type input').val() == 'undefined') {
		jQuery('#web_type input').val('tryfree');
	  }	
    } else {
	  jQuery("#set_website_hosted").hide();
	}
  });
  jQuery("#set_paid").hide();

  jQuery(".helptip img[title]").tooltip({ position: "top right", effect: "fade", opacity: 0.95});
  jQuery(".helptip-hdr img[title]").tooltip({ position: "top right", offset: [170, 50], effect: "fade", opacity: 1.0});

});

/*
// starting the script on page load
jQuery(document).ready(function(){
  imagePreview();

  jQuery('#website_hosted input').is(':checked') ? jQuery("div#set_website_hosted").show() : jQuery("div#set_website_hosted").hide();
  
  jQuery('#website_hosted input').click(function() {
	if (this.checked) {
	  jQuery("#set_website_hosted").show();
	  if (jQuery('#web_type input').val() == 'undefined') {
		jQuery('#web_type input').val('tryfree');
	  }	
    } else {
	  jQuery("#set_website_hosted").hide();
	}
  });
  jQuery("#set_paid").hide();

  jQuery(".helptip img[title]").tooltip({ position: "top right", effect: "fade", opacity: 0.95});
  jQuery(".helptip-hdr img[title]").tooltip({ position: "top right", offset: [170, 50], effect: "fade", opacity: 1.0});

  jQuery("#center-image").bind("load", function () {
	var screen_height =  Math.floor(screen.availHeight * 0.66);
	var screen_width =  Math.min(Math.floor(screen.availWidth * 0.6),Math.floor(parseInt($("#content").css("width")))*0.6);
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ver = navigator.appVersion;
		if (ver.substring(0,1) == '4') {
			screen_height =  Math.floor(screen.availHeight * 0.65);
			$("#main-content").css( { "height":screen_height } );
		}
	}
	var ratio = ($(this).height()/$(this).width()).toFixed(2);	//Image ratio
	if (ratio >= 0) { // lansdscape
		var this_width = Math.floor(screen_height/ratio);
		var this_height = Math.floor(this_width * ratio);
		if ((this_width+400)>screen_width) {
			screen_height = Math.floor(screen_height * (screen_width / (this_width+400) ));
		}
	  i_left =  Math.abs((screen_width - (screen_height/ratio))/2);
	  i_top	 =  Math.abs((screen_height - this_height)/2);
	} else { // portrait
	  i_left =  Math.abs((screen_width - (screen_height*ratio))/2);
	  i_top	 =  0;
	}
	var l_left = Math.floor((screen_width)/2);
	$(this).css( { "height":screen_height, "width":"auto","position":"absolute","top":i_top, "left":i_left, "z-index":2 } );
	$("#center-text").css( { "position":"fixed","left":l_left,"top":"45%","z-index":2,"font-size":"300%","color":"#FFF" } );
	$("#center-text").show();
	$(this).delay(900).fadeIn(10000);
  });
*/

});





