// JavaScript Document

	// <![CDATA[ 
	$(document).ready(function()
	{	

		// ---------------------------------------
		//
		// ---------------------------------------
		$('.popclick').click(function()
		{
			// determine the record id number by looking at the parent of the click entity (<a>).
			// Take the attribute value of id and extract the image_id value.
			//debugger;
			//pos = this.id;

			//var id = this.id.replace('popid-','');
			var id = $(this).attr('id').replace('popid-','');
			var classvalue = $('#popid-' + id).attr("href");
			
			//alert (classvalue);
			
			// If class is not pop'd then add a vote
			if(classvalue != "javascript:mmAlert();")
			{
			
				// Post the value of the href attr(ibute)
				// On the callback have echo(response) it to the id declared here.
				$.get("includes/buttonpop_add.php?v=1&image_id=" + id, {}, 
				function(response)
				{
		
					$('#poprating-' + id).html(unescape(response));
					//$('#poprating-' + id).fadeIn();	
		
					// update hyoerlink
					$('#popid-' + id).html("POP'D");
					$('#popid-' + id).attr("href", "javascript:mmAlert();");
									
				});
			}
						
		});
	
		// -----------------------------------------
		// Already voted
		// -----------------------------------------
		$('.popclick_popd').click(function()
		{
			alert("Thank you for your vote!. Please, rank other entries.");
		});
		
		
		// -----------------------------------------
		// If user has not logged in
		// -----------------------------------------
		$('.popclick_logout').click(function()
		{
			alert("Please, log in to be able to rank this entry.");
		});
		
		// Sider Pop Button functionality
		/*
		$('.spopclick').click(function()
		{
			// determine the record id number by looking at the parent of the click entity (<a>).
			// Take the attribute value of id and extract the image_id value.
			//debugger;
			//pos = this.id;
			
			//var id = this.id.replace('popid-','');
			var id = $(this).attr('id').replace('spopid-','');
			var classvalue = $('#spopid-' + id).attr("href");
			
			// Post the value of the href attr(ibute)
			// On the callback have echo(response) it to the id declared here.
						
			// If class is not pop'd then add a vote
			if(classvalue != "javascript:mmAlert();")
			{
			
				// Post the value of the href attr(ibute)
				// On the callback have echo(response) it to the id declared here.
				$.get("buttonpop_add.php?v=1&image_id=" + id, {}, 
				function(response)
				{
		
					$('#spoprating-' + id).html(unescape(response));
					//$('#poprating-' + id).fadeIn();	
		
					// update hyoerlink
					$('#spopid-' + id).html("POP'D");
					$('#spopid-' + id).attr("href", "javascript:mmAlert();");
									
				});
			}
		
		});
		*/
		
		// Already voted
		/*
		$('.spopclick_popd').click(function()
		{
			alert("Thank you for your vote !. Please, rank other entries.");
		});
		*/
	});	
	
	function mmAlert()
	{
		alert("Thank you for your vote !. Please, rank other entries.");
	}
	
	// Function for the menu
	function setSearchOptions(idElement)
	{
		/* Total Tabs above the input field (in this case there are 3 tabs: web, images, videos) */
		tot_tab = 3;
		tab = document.getElementById('tab' + idElement);
		search_option = document.getElementById('searchopt');
		
		//alert("here" + idElement);
		
		for(i=1; i<=3; i++)
		{
			if(i == idElement)
			{
				/*set class for active tab */
				tab.setAttribute("class","selected");
				/*set value for the hidden input element */
				search_option.value = idElement;
				
			} 
			else 
			{
				/*unset class for non active tabs */
				document.getElementById('tab' + i).setAttribute("class","");
			}
		}
	}

	// ----------------------------------------
	// This function works with the rating submit form.
	// ----------------------------------------
	function mmSubmitForm(voteresult)
	{
		document.getElementById("rating").value = voteresult;
		document.form_rating.submit();
	}
	
	// ]]>
