/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 10;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		
		if (this.href == 'http://www.crushme.com/browse.html#'){
			
			}else{
		$("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");		
			//.show();
			}
    },
	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");
	});	
	
	
	
	
};

function pop(userid, islogged, viewisonline, viewisfave, myid){
	
	
	var xmlHttp = ajaxFunction();
	
	xmlHttp.onreadystatechange=function (){
    
	if(xmlHttp.readyState==1)
      {
     
		  
		document.getElementById('profile_pop_ajaxgif').setAttribute('class', ''); 
		document.getElementById('profile_pop_ajaxgif').setAttribute('className', '');
		document.getElementById('profile_pop_ajaxgif').innerHTML = '<img src="/images/ajax-loader.gif">';
      }
		
    if(xmlHttp.readyState==4)
      {
      var response = xmlHttp.responseText;
	  var showpic = 'classes/phpthumb/phpThumb.php?';
	  var rarray = new Array();
	  rarray = response.split('|');
	  var username = rarray[0];
	  var age = rarray[1];
	  var imagesrc = '/' + showpic + 'src=' + rarray[2] + '&w=89&h=89&zc=1';
	  var vip = rarray[3];
	  
	  
	  document.getElementById("ajax_profileimagelink").href = '/' + username;
	  document.getElementById("ajax_profileimagelink").title = username;
	  document.getElementById("ajax_profileimage").src = imagesrc;
	  document.getElementById("ajax_profileimage").alt = username;
	  document.getElementById("ajax_usernamelink").innerHTML = username;
	  document.getElementById("ajax_usernamelink").title = username;
	  document.getElementById("ajax_usernamelink").href = '/' + username;
		document.getElementById("ajax_userage").innerHTML = 'AGE: ' + age;
		if (vip == 1){
			document.getElementById("ajax_vip").innerHTML = 'VIP MEMBER';
			}else{
			document.getElementById("ajax_vip").innerHTML = '';
			document.getElementById("ajax_vip_wrap").setAttribute('class', 'right vip hidden');
			document.getElementById("ajax_vip_wrap").setAttribute('className', 'right vip hidden');
			}
		
	  if (islogged == 1){
		  
			document.getElementById("ajax_addtofaveslink").onclick = function(){
			add_fave(myid, userid, '1');
			
				if (viewisonline == 1){
				document.getElementById(userid).setAttribute('class', 'online fave'); 
				document.getElementById(userid).setAttribute('className', 'online fave'); 
				}else{
				document.getElementById(userid).setAttribute('class', 'fave'); 
				document.getElementById(userid).setAttribute('className', 'fave'); 	
				}
		
			
			
			};
			document.getElementById("ajax_crushlink").onclick = function(){crush_member(userid, myid);};
			
		
		}else{
			
			document.getElementById("ajax_addtofaveslink").href = '/register.html';
			document.getElementById("ajax_crushlink").href = '/register.html';
			
		}
		
	
	  document.getElementById("ajax_viewprofilelink").title = username;
	  document.getElementById("ajax_viewprofilelink").href = '/' + username;
	  
	  document.getElementById('profile_pop_ajaxgif').setAttribute('class', 'hidden'); 
		document.getElementById('profile_pop_ajaxgif').setAttribute('className', 'hidden');
		document.getElementById('profile_pop_ajaxgif').innerHTML = '';
	  
		document.getElementById('profile_pop').setAttribute('class', ''); 
		document.getElementById('profile_pop').setAttribute('className', ''); 
		document.getElementById('popup_overlay').setAttribute('class', ''); 
		document.getElementById('popup_overlay').setAttribute('className', ''); 
		
		if (islogged == 1 && viewisfave != 1){
			if (viewisonline == 1){
			document.getElementById(userid).setAttribute('class', 'online viewed'); 
			document.getElementById(userid).setAttribute('className', 'online viewed'); 
			}else{
			document.getElementById(userid).setAttribute('class', 'viewed'); 
			document.getElementById(userid).setAttribute('className', 'viewed'); 	
			}
		}
		
		//document.getElementById('browse').style.visibility = 'hidden';
	  
      }
    }
	
	
	
		

		  
		  var url = 'ajax/ajax_functions.php?f=getmini&user=' + userid + '&loggedin=' + islogged + '&uid=' + myid;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
			//return false;

}

function unpop(){
	document.getElementById('profile_pop').setAttribute('class', 'hidden'); 
document.getElementById('profile_pop').setAttribute('className', 'hidden'); 
document.getElementById('popup_overlay').setAttribute('class', 'hidden'); 
document.getElementById('popup_overlay').setAttribute('className', 'hidden'); 
document.getElementById("ajax_return").innerHTML = '';
}

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