function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        // Base Url for localhost
        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        // Root Url for domain name
        return baseURL + "/";
    }

}



//-----------------------------------------------------
function doClear(theField) {
	if (theField.value == theField.defaultValue) {
		theField.value = "";
	}
	
	theField.style.color = "#FFF";
	theField.setAttribute("autocomplete", "off");
}

function doRecall(theField) {
	if (theField.value == "") {
		theField.value = theField.defaultValue;
		theField.style.color = "#8ACABC";
	}
}








//-----------------------
function onloading(div) {
	document.getElementById(div).style.display = "block";
}

//-----------------------
function stoploading(div) {
	document.getElementById(div).style.display = "none";
}






//--------------------------------------------
function AJAX()
{
  var request = null;
   
  if(typeof window.XMLHttpRequest != "undefined")
  {
    request = new XMLHttpRequest();
  }
  else if(typeof window.ActiveXObject 
      != "undefined")
  {
    try
    {
      request = new 
          ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(err) { request = null; }
  }
   
  return request;
}




//--------------
function refreshFave() {

	var xmlHttp_three = AJAX();

	xmlHttp_three.onreadystatechange = function(){
		if(xmlHttp_three.readyState == 4){
			document.getElementById('userDiv').innerHTML = xmlHttp_three.responseText;
			
			stoploading('spinner');
		}
	}

	var queryString_three = getBaseURL()+"ajax_fave_user.php?";
	xmlHttp_three.open("GET",queryString_three,true);
	xmlHttp_three.send(null);
	
}

//--------------
function favethis() {
	
	onloading('spinner');
	
	var xmlHttp_one = AJAX();

	xmlHttp_one.onreadystatechange = function(){
		if(xmlHttp_one.readyState == 4){
			document.getElementById('ajaxDiv').innerHTML = xmlHttp_one.responseText;
			refreshFave();
		}
	}
	
	var favexx = document.getElementById('fave-this').value;
	var queryString = getBaseURL()+"ajax_fave.php?favethis=" + favexx;
	xmlHttp_one.open("GET",queryString,true);
	xmlHttp_one.send(null);
	
	//event.preventDefault();
	//event.returnValue = false;
}

//--------------
function unfavethis() {
	
	onloading('spinner');
	
	var xmlHttp_two = AJAX();

	xmlHttp_two.onreadystatechange = function(){
		if(xmlHttp_two.readyState == 4){
			document.getElementById('ajaxDiv').innerHTML = xmlHttp_two.responseText;
			refreshFave();
		}
	}
	
	var favexx = document.getElementById('unfave-this').value;
	var queryString = getBaseURL()+"ajax_unfave.php?unfavethis=" + favexx;
	xmlHttp_two.open("GET",queryString,true);
	xmlHttp_two.send(null);
	
	//event.preventDefault();
	//event.returnValue = false;
}












//---------------------------------
$(document).ready(function() {
	
	//alert('JQuery Ready!');
	
	/*
	//--- testing ----------------
	$('#stuff').toggle(function() {
		
		$(this).animate({ marginLeft: '+=200px'}, 500, 'swing');
		
	}, function() {
		
		$(this).animate({ marginLeft: '-=200px'}, 500, 'swing');
		
	})
	//--- testing end ---------------
	*/
	
	$('#stuff').mouseover(function() {
		$('.follow').fadeIn('fast');
	});
	
	$('#stuff').mouseout(function() {
		$('.follow').hide();
	});
	
	$('#stuff').mousemove(function(e) {
		$('.follow').css('top', e.clientY).css('left', e.clientX);
	});
	
	
	
	
	
	/* big submit button tooltip*/
	$('#submit_big_wrap2').mouseover(function() {
		$('.nosubmit').fadeIn('fast');
	});
	
	$('#submit_big_wrap2').mouseout(function() {
		$('.nosubmit').hide();
	});
	
	$('#submit_big_wrap2').mousemove(function(e) {
		$('.nosubmit').css('top', e.clientY).css('left', e.clientX);
	});
	
	
	
	
	/* tooltip */
	for(var i=1; i<=48; i++) {
		$('#vl-'+i).mouseover(function() {
			var num = this.id.substring('vl-'.length);
			$('#vl-'+num+' a').removeAttr('title');
			$('.vpop-'+num).show();
			//alert(num);
		});
		
		$('#vl-'+i).mouseout(function() {
			var num = this.id.substring('vl-'.length);
			$('.vpop-'+num).hide();
		});
		
		$('#vl-'+i).mousemove(function(e) {
			var num = this.id.substring('vl-'.length);
			$('.vpop-'+num).css('top', e.clientY).css('left', e.clientX);
		});
	}
	
	/* tooltip medium image */
	for(var i=1; i<=48; i++) {
		$('#inl-'+i).mouseover(function() {
			var num = this.id.substring('inl-'.length);
			$('#inl-'+num+' a').removeAttr('title');
			$('.inpop-'+num).show();
			//alert(num);
		});
		
		$('#inl-'+i).mouseout(function() {
			var num = this.id.substring('inl-'.length);
			$('.inpop-'+num).hide();
		});
		
		$('#inl-'+i).mousemove(function(e) {
			var num = this.id.substring('inl-'.length);
			$('.inpop-'+num).css('top', e.clientY).css('left', e.clientX);
		});
	}
	
	
	
	
	


	
	
	
	
	$('#share_wrap').css('marginLeft','-90px');
	
	$('.share_box_btn').toggle(function() {
		$('#share_wrap').animate({ marginLeft: '+=90px'}, 100, 'swing');
	}, function() {
		$('#share_wrap').animate({ marginLeft: '-=90px'}, 100, 'swing');
	});

	/*
	$('body').click(function() {
		var marginLeft = $('#share_wrap').css('marginLeft');
		//alert(marginLeft);
		
		if(marginLeft == '0px') {
			$('#share_wrap').animate({ marginLeft: '-=90px'}, 100, 'swing');
		}
	});
	*/

});











