/*
 * Copyright by Deacix Media, Sergej Kunz
 * http://www.deacix-media.de
*/

$.include(BASE_PATH+'/js/fancyzoom.min.js');
$.include(BASE_PATH+'/js/jquery.Jcrop.min.js');
$.include(BASE_PATH+'/js/jquery.tooltip.min.js');
//$.include(BASE_PATH+'/js/messaging_system2.js');
$.include(BASE_PATH+'/js/jquery.info-box.js');
$.include(BASE_PATH+'/js/jquery.send-form.js');
$.include(BASE_DIR+'/js/lib/functions.lib.min.js');
//$.include(BASE_DIR+'/js/live.min.js');
$.include(BASE_DIR+'/js/loadingLayer.min.js');

$(function() {
    var initializing = function() {
    	initLoadingLayer();
    	//$('#bt_mail').initMessagingSystem();
    	
    	/* Contacts Online 
    		$.get(BASE_PATH+"/com.php?com=ajax_get_contacts_online", function(ajax_birth_users_html){
    			$("#ajax_contacts_online").fadeOut('slow', function() {
    				$("#ajax_contacts_online").html(ajax_birth_users_html);
    				$('#ajax_contacts_online').initToolTip();
    				$("#ajax_contacts_online a").prepend("<span></span>");
    				
    				$("#ajax_contacts_online").fadeIn('slow');
    			});
    		});
    	 END */
    	
    	/* Last Pics 
    		$.get(BASE_PATH+"/com.php?com=ajax_get_last_pics", function(ajax_last_pics_html){
    			$("#ajax_last_pics").hide('slow', function() {
    				$("#ajax_last_pics").html(ajax_last_pics_html);
    				$('#ajax_last_pics').initToolTip();
    				$("#ajax_last_pics a").prepend("<span></span>");
    				
    				$("#ajax_last_pics").show('slow');
    			});
    		});
    	 END */
    	
    	/* New Members 
    		$.get(BASE_PATH+"/com.php?com=ajax_get_new_members_users", function(ajax_new_members_html){
    			$("#ajax_new_members").hide('slow', function() {
    				$("#ajax_new_members").html(ajax_new_members_html);
    				$('#ajax_new_members').initToolTip();
    				$("#ajax_new_members a").prepend("<span></span>");
    				
    				$("#ajax_new_members").show('slow');
    			});
    		});
    	 END */
    	
    	/* Birthday Users 
    		$.get(BASE_PATH+"/com.php?com=ajax_get_birthday_users", function(ajax_birth_users_html){
    			$("#ajax_birthday_users").hide('slow', function() {
    				$("#ajax_birthday_users").html(ajax_birth_users_html);
    				$('#ajax_birthday_users').initToolTip();
    				$("#ajax_birthday_users a").prepend("<span></span>");
    				
    				$("#ajax_birthday_users").show('slow');
    			});
    		});
    	 END */
    	
    	/* Random Users 
    		$.get(BASE_PATH+"/com.php?com=ajax_get_random_users", function(ajax_random_users_html){
    			$("#ajax_random_users").hide('slow', function() {
    				$("#ajax_random_users").html(ajax_random_users_html);
    				$('#ajax_random_users').initToolTip();
    				$("#ajax_random_users a").prepend("<span></span>");
    				
    				$("#ajax_random_users").show('slow');
    			});
    		});
    	 END */
    	
    	/* Last Visitors 
    		$.get(BASE_PATH+"/com.php?com=ajax_get_last_visitors", function(ajax_birth_users_html){
    			$("#ajax_last_visitors").fadeOut('slow', function() {
    				$("#ajax_last_visitors").html(ajax_birth_users_html);
    				$('#ajax_last_visitors').initToolTip();
    				$("#ajax_last_visitors a").prepend("<span></span>");
    				
    				$("#ajax_last_visitors").fadeIn('slow');
    			});
    		});
    	 END */
    	
    	/* Online Random Users
    		$.get(BASE_PATH+"/com.php?com=ajax_get_online_random_users", function(ajax_local_users_online_html){
    			$("#ajax_local_users_online").hide('slow', function(){
    				$("#ajax_local_users_online").html(ajax_local_users_online_html);
    				$('#ajax_local_users_online').initToolTip();
    				$("#ajax_local_users_online a").prepend("<span></span>");
    				
    				$("#ajax_local_users_online").show('slow');
    			});
    		});
    	END */
    	
    	 $(".photo a").prepend("<span></span>");
    	 $(".photo_75x100 a").prepend("<span></span>");
         
         $('.link_tooltip a').tooltip({ 
    	    track: true, 
    	    delay: 0, 
    	    showURL: false, 
    	    fade: 250 
    	});
         
         $('#group_title_tool_tip').tooltip({ 
    	    track: true, 
    	    delay: 0, 
    	    showURL: false, 
    	    fade: 250 
    	});
    	
    	$('.image_tooltip').initToolTip();
    	
    	$('a.zoom').fancyZoom({
    		directory: BASE_PATH+'/graphics/DesignContent/LightBox',
    		scaleImg: false, 
    		closeOnClick: true
    	});
    	
    	/* SMS Form */
    		$('.smsform #sms_message').keyup(function(e) {
    			var elem = jQuery(this);
    			var text = elem.val();
    	
    			if(text.length <= 120) {
    				elem.parent().find('#smsTextCharsCounter').attr('value', text.length);
    			} else {
    				elem.val(text.substr(0, 120));
    			}
    		});
    	/* END */
    		
    	$('.next-level').each(function() {
    		new Ext.ToolTip({
    			target: this,
    			anchor: 'top',
    			trackMouse: true,
    			html: $(this).attr('title')
    		});
    		
    		$(this).removeAttr('title');
    	});	
    };
    
    jQuery.fn.initToolTip = function() {
    	var $container = jQuery(this);
    	
    	$container.find('a').tooltip({ 
    	    delay: (360*2), 
    	    fade: 0,
    	    showURL: false, 
    	    bodyHandler: function() { 
    	    	var link = jQuery(this);
    	        var url = link.attr('rev');
    	        if(!url) {
    	        	url = link.find('img').attr('src');
    		        if(url) {
    					url = url.substr(0, url.length);
    					url = url.substr(0, url.indexOf("_"));
    					
    			        result =  url+'_240x320.jpg'; 
    				} else {
    					result = false;
    				}
    			} else {
    				result = url;
    			}
    			
    			return $("<img/>").attr("src", result); 
    	    } 
    	});

    	$('#search').click(function() {
    	    var elem = $(this);
    	    elem.val('');
    	}); 
    };
    
    initializing();
});