
if(!window.Position){

	var Position = {
	
	  cumulativeOffset: function(element) {
	    var valueT = 0, valueL = 0;
	    do {
	      valueT += element.offsetTop  || 0;
	      valueL += element.offsetLeft || 0;
	      element = element.offsetParent;
	    } while (element);
	    return [valueL, valueT];
	  }
	}

}

if(!window.$){

	function $(id) {
		if(typeof id == "string"){
			return document.getElementById(id);
		}
		else{
			return id;
		}
	}

}

function pawsUp(link){

	YAHOO.util.Connect.asyncRequest('POST', domain + "articles/vote", null, "link="+link);

	//$('MainVotingBox_' + link).style.border = "1px solid #f08";
	$('VoteCountBox_'+link).innerHTML = parseInt($('VoteCountBox_'+link).innerHTML) + 1;
	$('VoteLink_' + link).innerHTML = "Paws&nbsp;Up!";
	
}

function pawsUpVideo(link){
	
	YAHOO.util.Connect.asyncRequest('POST', domain + "video/vote", null, "video="+link);

	//$('VideoCountBox_' +link).style.backgroundImage = "url(" + domain + "resources/images/icons/paw4.gif)";
	$('VideoCountBox_'+link).innerHTML = parseInt($('VideoCountBox_'+link).innerHTML) + 1;
	$('VideoLink_' + link).innerHTML = "Paws&nbsp;Up!";
	
}

function pawsUpPost(comment){
	
	YAHOO.util.Connect.asyncRequest('POST', domain + "forums/vote", null, "post="+comment);

	
	$('VoteCountBox_'+ comment).innerHTML = parseInt($('VoteCountBox_'+comment).innerHTML) + 1;
	$('VoteLink_' + comment).innerHTML = "Paws&nbsp;Up!";
	
}


function pawsUpTopic(comment){
	
	YAHOO.util.Connect.asyncRequest('POST', domain + "forums/votetopic", null, "topic="+comment);

	$('VoteCountTopicBox').innerHTML = parseInt($('VoteCountTopicBox').innerHTML) + 1;
	$('VoteLinkTopic').innerHTML = "Paws&nbsp;Up!";
	
}

function pawsUpStory(story){
	
	YAHOO.util.Connect.asyncRequest('POST', domain + "stories/vote", null, "story="+story);

	$('StoryCountBox_'+story).innerHTML = parseInt($('StoryCountBox_'+story).innerHTML) + 1;
	$('StoryLink_' + story).innerHTML = "Paws&nbsp;Up!";

}

function pawsUpGallery(pic){
	
	YAHOO.util.Connect.asyncRequest('POST', domain + "gallery/vote", null, "picture="+pic);

	$('PictureCountBox_'+pic).innerHTML = parseInt($('PictureCountBox_'+pic).innerHTML) + 1;
	$('PictureLink_' + pic).innerHTML = "Paws&nbsp;Up!";

}

function popupHelp(msgType, link, showAbove){

	var titles = {'popular': "How do I get to show up on “I’m SO Popular Today”?",
			    	'video' : "What does it mean to participate and why should I care?",
					'pikapoints' : "What are Pikapoints?"};
				  
	var messages = {'popular': "You become the most popular pet if you were the pet with the most new pals and add to favorites of the day.  Sometimes being cute is not enough, but interacting with other pets helps a lot too!",
					'video' : "Pikapet is a user-driven site.  Yes, that means you..  :)  Users submit content "+
							"and vote for the best.  If you find a great link or video that you would like to "+
							"share, please do so here.  Users will give you “paws up” if they like it and we "+
							"will give you Pikapoints for every “Paws Up”.  Also, if the content you suggest "+
							"is the best-voted of the day, you get bonus Pikapoints.  How cool is that?",
					'pikapoints' : "The points you accumulate by participating in the different sections of our site "+
									"are called Pikapoints. They are part of our Pikapet Rewards Auction and allow you to claim the products and services offered by our sponsors. "+
									"Please note that "+
									"Pikapoints don’t have any economic value. "+
									"To learn more about Pikapoints and our Rewards Auction, please see the "+
									"<a  href='" +domain + "home/faq' style='color:white'>FAQ</a>"};

		
	var mark = $('helpMarkPopup');
	
	if(mark.style.display == "block"){
		mark.style.display = "none";
		return;
	}
	
	mark.innerHTML = "<div style='font-weight:bold' onmouseover='keepShowingMark()'>"+titles[msgType] + "</div>" + messages[msgType];
	
	mark.style.display = "block";

	var linkPos = Position.cumulativeOffset(link);
	
	mark.style.left = linkPos[0] + "px";
	
	if(showAbove){
		mark.style.top = linkPos[1] - mark.offsetHeight + "px";
	}
	else{
		mark.style.top = linkPos[1] + 18 + "px";
	}
	
	mark.style.zIndex = 100;

	
}

function keepShowingMark(){
	var mark = $('helpMarkPopup');
	mark.style.display = "block";
}

function closeHelpMark(mark){
	mark.style.display = "none";
}


	function showTooltip(){
		positionateTooltip();
		$('tooltip').style.visibility = "visible";
	}
	
	function hideTooltip(){
		if($('tooltip'))
			$('tooltip').style.visibility = "hidden";		
	}

	function positionateTooltip(){

		var container = $('mainPictureContainer');

		if(!container){
			container = $('mediaZone');
		
		}
		
		var position = Position.cumulativeOffset(container);
		
		var tooltip = $('tooltip');
		
		if(tooltip){
			tooltip.style.left = position[0] - tooltip.offsetWidth/2 + container.offsetWidth/2 + "px";
			tooltip.style.top = position[1] - tooltip.offsetHeight + 8 + "px";
			pageLoaded = true;
		}
		
	}