searchtext = function()
{
	var box = $("#q");
	var boxText = box.val();
	box.focus(function() { 
		if(boxText) { 
			box.val('').css('background-color', '#FDFAFC'); 
		} 
	});	
	box.blur (function() { 
		if(box.val() == '') { 
			box.val(boxText).css('background-color', '#FFF'); 
		} 
	});	
}


onHover = function(elem, className)
{
	if(!className) {
		var className = 'onHover';
	}
	$(elem).hover(function() {
		$(this).addClass(className);
	}, function() {
		$(this).removeClass(className);
	});
}

contact = function()
{
    var form = $("#contactForm").serialize();
    $("#contact").html('Processing. Please, wait...');
	$.ajax({
	   type: "POST",
	   url: HOMEPAGE + '/contact/',
	   data: "data=" + escape(form),
	   success: function(msg){
	     $("#contact").html(msg);
	   }
	 });	
}


login = function() {
	var form = $("#loginForm").serialize();
	$("#login").html('Please, wait...');
	$.ajax({
		type: "POST",
		url: HOMEPAGE + '/loginbox/',
		data: "data=" + escape(form),
		success: function(msg) {
			$("#TB_ajaxContent").html(msg);
		}
	});	
}


hideInfo = function(div)
{
	$(div).hide();
}


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = 10;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


String.prototype.toPHP = function() 
{ 
	var s = this;
	s=s.replace(/\\/g, "\\\\");
	s=s.replace(/\"/g, "\\\"");
	s=s.replace(/\n/g, "\\n");
	s=s.replace(/\r/g, "");
	return 's:'+s.length+':"'+s+'";'
}

fetchSlider = function()
{
    $('#s3slider').s3Slider({ timeOut: 8000 });
}


$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};    


// force to open in new window
targetBlank = function() {
	$(".tBlank").bind('click', function() {
		$(this).attr('target', '_blank');
	});
}



$(window).load(function()
{
	searchtext();
	tooltip();
	if($('#s3slider').html() != null) {
		fetchSlider();
	}
	$("#boxes ul li div.inner").hoverClass('hovered');
    targetBlank();
    
	$('#navigation li.primary').hover(
		function() { $('ul', this).show();  },
		function() { $('ul', this).hide(); }
	);
});
