$(document).ready(function() {
	imagePreview();
	if($j(".my_class").height()>351)
		$j("div.jScrollPaneContent").jScrollPane({scrollbarWidth:9});
});

function closeClick() {
	if($j("#Overlay").hasClass("closed")) {
		$j("#Overlay").fadeOut(1000);
	} else {
		slideOverlay("right");
	}
}

function slideOverlay(direction) {
	if(direction=="left") {
		if($j("#Overlay").css("right")=="0px")
			return;
		
		$j("#Overlay").animate({
			right: "0px"
		},1000);
		
		$j("#Overlay .container:visible").each(function() {$(this).fadeOut(1000);});
		$j("#Overlay").removeClass("closed");
	} else {
		$j("#Overlay").animate({
			right: "-248px"
		},1000);
		
		$j("#Overlay .container:visible").each(function() {$(this).fadeOut(1000);});
		$j("#Overlay").addClass("closed");
	}
}

function infoClick () {
	if($j("#Overlay:visible").length==0) {
		$j("#Overlay").fadeIn(1000);
	}

	if($j("#Overlay .container:visible").attr("id")=="infoContainer")
		return;

	if($j("#VideoPopup").length>0)
		$("#VideoPopup").jqmHide();
	
	$j("#ButtonContainer .button.selected").removeClass("selected");
	$j("#ButtonContainer .infoButton").addClass("selected");

	slideOverlay("left");
	
	$j("#infoContainer").fadeIn(1000);
	
	$j("#ImageContainer .imageContent:visible").fadeOut(1000);
	$j("#ImageContainer .infoImage").fadeIn(1000);
}

function globeClick() {
	$j("#Overlay").fadeOut(1000);
	
	if($j("#Overlay .container:visible").attr("id")=="globeContainer")
		return;

	if($j("#VideoPopup").length>0)
		$("#VideoPopup").jqmHide();
	
	$j("#ButtonContainer .button.selected").removeClass("selected");
	$j("#ButtonContainer .globeButton").addClass("selected");
	
	$j("#Overlay .container:visible").each(function() {$(this).fadeOut(1000);});
	
	$j("#ImageContainer .imageContent:visible").fadeOut(1000);
	$j("#ImageContainer .globeContent").fadeIn(1000);
}

function circleClick() {
$j("#Overlay").fadeOut(1000);
	
	if($j("#Overlay .container:visible").attr("id")=="circleContainer")
		return;
	
	if($j("#VideoPopup").length>0)
		$("#VideoPopup").jqmHide();

	$j("#ButtonContainer .button.selected").removeClass("selected");
	$j("#ButtonContainer .circleButton").addClass("selected");
	
	$j("#Overlay .container:visible").each(function() {$(this).fadeOut(1000);});
	
	$j("#ImageContainer .imageContent:visible").fadeOut(1000);
	$j("#ImageContainer .circleContent").fadeIn(1000);
}

this.imagePreview = function(){    
    /* CONFIG */
          
          xOffset = 10;
          yOffset = 30;
          
          // these 2 variable determine popup's distance from the cursor
          // you might want to adjust to get the right result
    /* END CONFIG */
    $j("a.preview").hover(function(e){
          $j("body").append("<div id='preview'>"+ this.name + "</div>");                                               
          $j("#preview")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px")
                .fadeIn("fast");                               
  },
    function(){ 
          $j("#preview").remove();
  });     
    $j("a.preview").mousemove(function(e){
          $j("#preview")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px");
    });               
};
