/* DOMReady */
$(function () {
  
	
	/*** index ***/
  
	var params  = { 
		scale: 'noScale', 
		background: '0x000000', 
		salign: 't', 
		wmode:'transparent',
		allowFullScreen: 'true',
       allowScriptAccess: 'always'
	};
	var flashvars = { flvUrl:'overthere.flv' };
	swfobject.embedSWF("Landing.swf", "flashreplace", "1024", "898", "9.0.0","expressInstall.swf",flashvars,params);
	swffit.fit("flashreplace",1024,898); 	
	//alert(location.href);
	//var u = (location.href).split("#",1)
//	shorten(u);
	//shorten("http://www.lhj.com/relationships/can-this-marriage-be-saved/kids/i-wasnt-excited-about-my-new-baby/");
});


function fb_click(lang) {
  theurl=(location.href).split("#")[0];
  //t=document.title;
  window.open('http://www.facebook.com/sharer.php?t='+lang+'&u='+theurl,'facebookwindow','height=304,width=440');
  return false;
}


function twit_click(lang) {
	//alert("twitclick:"+lang);
  theurl=(location.href).split("#")[0];
  hash=(location.href).split("#")[1];
  var defaults = {
    version:    '2.0.1',
    login:      'breed10',
    apiKey:     'R_08ff8c6399bf0fa83d4c08a82f024b26',
    history:    '0',
    longUrl:    theurl
  };
  
  // Build the URL to query
  var daurl = "http://api.bit.ly/shorten?"
    +"version="+defaults.version    
    +"&login="+defaults.login
    +"&apiKey="+defaults.apiKey
    +"&history="+defaults.history
    +"&format=json&callback=?"
	+"&longUrl="+defaults.longUrl;

    // Utilize the bit.ly API
    $.getJSON(daurl, function(data){
		
		//alert(data.results[theurl].shortUrl);
		shortURL = encodeURIComponent(data.results[theurl].shortUrl + "#" + hash);
		//alert(shortURL);
		window.open("http://twitter.com/home?status=" + lang + shortURL,'twittershare','height=400,width=800');
		//window.open("http://twitter.com/home?status=" + encodeURIComponent(lang) + shortURL,'sharer');
		//
		//	alert (data.results[theurl].shortUrl);
		//	return data.results[theurl].shortUrl;


    });
 
  return false;
}

function lhj_click() {
  window.open('http://www.lhj.com');
  return false;
}

/*popup functions*/
function popupComments() {
    s=(location.href).split("#")[1].replace("/","");
    fbinit(s);
	$("#popup").css("width", "693px");
	//$("#popup").css("top", "559px");
	$("#popup").css("left", "166px");
	//window.scrollTo(28,46);
	//centering with css
	centerPopup();
	//load popup
	loadPopup("comments");
        return false;
}

var popupStatus = 0;

//loading popup
function loadPopup(contentID){

	if(popupStatus==0) {

		$("#popup div.popup_content").hide();
		$("#popup_bg").css({
			"opacity": "0.7"
		}); 
		$("#popup_bg").fadeIn("slow");
		$("#popup").fadeIn("slow");
		$("#popup_content_" + contentID).show();
		popupStatus = 1;
	}

	return false;
}

//disabling popup
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
	$("#popup_bg").fadeOut("slow");
		$("#popup").fadeOut("slow");
		popupStatus = 0;
	}
	return false;
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup").height();
	var popupWidth = $("#popup").width();
	//centering
	$("#popup").css({
		"position": "absolute",			   
		"left": windowWidth/2-popupWidth/2
		/*"position":"absolute",
		"left":"32px"*/
	});
	//only need force for IE6
   	    	var myheight = windowHeight + document.documentElement.scrollHeight;
   		$("#popup_bg").css({
		"height": myheight
	});
}

function submitComments()
{
//	var comment_name = $("#comment_name").val();
	var comment_comment = $("#comment_comment").val();
	//alert("comment_name = " + comment_name + ", comment_comment = " + comment_comment);
	var page = window.location.href;
	var post_address = "sendComment.php";

	if (comment_comment.length > 0)
	{
		$.ajax({
			type: "GET",
			url: post_address,
			data: "comment=" + comment_comment,
			success: function(msg){
			if(msg=="Success=true")
			{
		
			}else{
				alert("Failure\n"+msg);
				}
		}		
		});
	}
	disablePopup();	
}

/*end popup functions*/


function shorten(theurl) {
  // set up default options
  //alert(theurl);
  var defaults = {
    version:    '2.0.1',
    login:      'breed10',
    apiKey:     'R_08ff8c6399bf0fa83d4c08a82f024b26',
    history:    '0',
    longUrl:    theurl
  };
  
  // Build the URL to query
  var daurl = "http://api.bit.ly/shorten?"
    +"version="+defaults.version    
    +"&login="+defaults.login
    +"&apiKey="+defaults.apiKey
    +"&history="+defaults.history
    +"&format=json&callback=?"
	+"&longUrl="+defaults.longUrl;

    // Utilize the bit.ly API
    $.getJSON(daurl, function(data){
	
			//
			alert (data.results[theurl].shortUrl);
			return data.results[theurl].shortUrl;
	

    });
}

function isdefined( variable)
{
    return (typeof(window[variable]) == "undefined")?  false: true;
}

