jQuery.noConflict();

/*
jQuery(document).ready(function() {
	jQuery('form').submit(function(){
		jQuery(this).find("input[type='image'],input[type='submit']").click(function(){
			return false;
		});
	}); 
	jQuery(".voteform").submit( function(ev) {
		ev.preventDefault();
		var dataString = jQuery(this).serialize();
		jQuery.ajax({  
			type: "POST",  
			url: "/resource/templates/contest/vote.cfm",  
			data: dataString,  
			success: function(msg) {  
				jQuery("submit").hide();
			}
		});
	});
});
*/

//popup functions	
var popupStatus = 0;
var currentpage = 1;
/*
function showdiv(pagecount,divid) {
	var i = 1;
	for (i=1;i<=pagecount;i++) {
		jQuery("#"+i+"div").hide('fast');
		jQuery("#"+i+"diva").css("font-weight","normal");
	}
	jQuery("#"+divid).show('fast');
	jQuery("#"+divid+"a").css("font-weight","bold");
	currentpage = divid;
}*/

function showdiv(goto){
	jQuery("#"+currentpage+"div").hide('fast');
	jQuery("#"+currentpage+"diva").css("font-weight","normal");
  jQuery("#"+currentpage+"divb").css("font-weight","normal");
	jQuery("#"+goto+"div").show('fast');
	jQuery("#"+goto+"diva").css("font-weight","bold");
	jQuery("#"+goto+"divb").css("font-weight","bold");
	currentpage = goto;
}
function shownext(num){
	if (currentpage != num){		
		jQuery("#"+currentpage+"div").hide('fast');
		jQuery("#"+currentpage+"diva").css("font-weight","normal");
		jQuery("#"+currentpage+"divb").css("font-weight","normal");
		currentpage++;
		jQuery("#"+currentpage.toString()+"div").show('fast');
		jQuery("#"+currentpage.toString()+"diva").css("font-weight","bold");
		jQuery("#"+currentpage.toString()+"divb").css("font-weight","bold");
	}
}
function showprevious(num){
	if (currentpage > 1){		
		jQuery("#"+currentpage+"div").hide('fast');
		jQuery("#"+currentpage+"diva").css("font-weight","normal");
		jQuery("#"+currentpage+"divb").css("font-weight","normal");
		currentpage--;
		jQuery("#"+currentpage.toString()+"div").show('fast');
		jQuery("#"+currentpage.toString()+"diva").css("font-weight","bold");
		jQuery("#"+currentpage.toString()+"divb").css("font-weight","bold");
	}
}
function loadPopup(image,folder,username,caption,userid,mediaid,votes,caption2,cityState){   
//loads popup only if it is disabled   
	if(popupStatus==0){
		centerPopup();
		//$("#popupVote").html(page);
		jQuery("#bigimage").attr("src","/resource/images/" + folder + "/contest/photos/"+image);
		jQuery("#user").html(username);
		jQuery("#cityState").html(cityState);
		jQuery("#caption").html(caption);
		jQuery("#mediaidp").html(mediaid);
		jQuery("#photocaption").html(caption2);
		jQuery("#votecount").html("Votes: "+votes);
		jQuery("#backgroundPopup").show("fast");
		jQuery("#popupVote").show("fast");
		popupStatus = 1;
		//because of asynchronous nature, applies the close function to links in the text
		jQuery("#popupVoteClose").click(function(){   disablePopup();   });
		/*
		jQuery("#voteform").submit( function() {
			var dataString = jQuery("#voteform").serialize();
			jQuery.ajax({  
				type: "POST",  
				url: "/resource/templates/contest/vote.cfm",  
				data: dataString,  
				success: function(msg) {  
					jQuery("#votecount").html("Votes:" + msg);
					jQuery("#"+mediaid).html(msg);
					jQuery("submit").hide();
					location.reload(true);
				}
			});
		 
		 return false;
		 });  
		*/
	}   
}
function disablePopup(){   //disables popup only if it is enabled   
	if(popupStatus==1){   
		jQuery("#backgroundPopup").hide("fast");   
		jQuery("#popupVote").hide("fast");
		jQuery("#bigimage").attr("src","");
		popupStatus = 0;   
	}
}
function centerPopup(){   //request data for centering   
	var windowWidth = document.documentElement.clientWidth;   
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = jQuery("#popupVote").height();   
	var popupWidth = jQuery("#popupVote").width();   
	//centering   
	jQuery("#popupVote").css({   "position": "absolute",   "top": "300px",   "left": windowWidth/2-popupWidth/2   });   
	//only need force for IE6     
	jQuery("#backgroundPopup").css({   "height": windowHeight   });
	window.location.hash = "#windowtop";
}
var leaderboardstatus = 0;
function loadLeaderboard(){
	if(leaderboardstatus==0){
		centerLeaderboard();
		jQuery("#popupLeaderBoardClose").click(function(){   disableLeaderboard();   });
		jQuery("#backgroundPopup").show("fast");
		jQuery("#popupLeaders").show("fast");
		leaderboardstatus = 1;
	}
}
function disableLeaderboard() {
	if(leaderboardstatus==1){
		jQuery("#backgroundPopup").hide("fast");   
		jQuery("#popupLeaders").hide("fast");   
		leaderboardstatus = 0;
		//location.reload();
	}
}
function centerLeaderboard(){   //request data for centering   
	var windowWidth = document.documentElement.clientWidth;   
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = jQuery("#popupLeaders").height();   
	var popupWidth = jQuery("#popupLeaders").width();   
	//centering   
	jQuery("#popupLeaders").css({   "position": "absolute",   "top": "300px",   "left": windowWidth/2-popupWidth/2   });   
	//only need force for IE6     
	jQuery("#backgroundPopup").css({   "height": windowHeight   });    
	document.location.hash = "#windowtop"; 
}

function voteLanding(mediaid, userid, CON_ID){
	$(mediaid).fade({ duration: 1.5, from: 1, to: .2 });
	var url = '/resource/templates/contest/vote.cfm';
	var params = 'userid=' + userid + '&mediaid=' + mediaid + '&CON_ID=' + CON_ID;
	var ajax = new Ajax.Updater({success: mediaid},url,{method: 'get', parameters: params,onComplete: 
		function(request){ 
			$(mediaid).appear({ duration: 0.5 });
			location.reload();			
		}
	});
	
}
