// make browser information object
var BrowserDetect={init:function(){this.browser=this.searchString(this.dataBrowser)||"An unknown browser";this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version";this.OS=this.searchString(this.dataOS)||"an unknown OS";},searchString:function(data){for(var i=0;i<data.length;i++){var dataString=data[i].string;var dataProp=data[i].prop;this.versionSearchString=data[i].versionSearch||data[i].identity;if(dataString){if(dataString.indexOf(data[i].subString)!=-1)
return data[i].identity;}
else if(dataProp)
return data[i].identity;}},searchVersion:function(dataString){var index=dataString.indexOf(this.versionSearchString);if(index==-1)return;return parseFloat(dataString.substring(index+this.versionSearchString.length+1));},dataBrowser:[{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone/iPod"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};
BrowserDetect.init();
///////////////////////////////////


var ajaxWaitingImage = "<img src=\"/images/ajax-loader.gif\" />";
var the_helper_cookie;

function isDefined( variable ){
    return (typeof(window[variable]) == "undefined")?  false: true;
}
/************************************* Tools method *************************************************/
function timedRedirection(url, second){
	var time = second * 1000;
	var t = setTimeout("location.href='" + url + "';", time);
}

function showHelper(){
	$("#collapse").show();
	$("#expand").hide();
	setCookie("the_helper_cookie", "show"); 
}

function hideHelper(){
	$("#collapse").hide();
	$("#expand").show();
	setCookie("the_helper_cookie", "hide");
}

function limitChars(textid, limit, infodiv){
	var text = $("#" + textid).val(); 
	var textlength = text.length;
	if(textlength > limit){
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	}else{
		$('#' + infodiv).empty().html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

function hoverMenu(target) {
	if ($(target).hasClass("hover") == true) {
		$(target).removeClass("hover");
	} else {
		$(target).addClass("hover");
	}
}

function reportAbuse(){
	if($("#l").val()==0){
		var title = "You've got to login or join AZUDOO to do that";			
		var message = "You will have to login to report an abuse on AZUDOO website. Click here to <a href='/login'>login</a>";
		displayAttentionMessage(title, message);

	}else{
	
		var title = "Report this page";
		var message = "Do you feel that this content is inappropriate?<br /><br />Please help us maintain the integrity of AZUDOO by reporting inappropriate behavior by selecting the type of content below.";
	
		message += "<br /><br /><select id=\"reason\">";
		message += "	<option value='Hateful or abusive content'>Hateful or abusive content</option>";
		message += "	<option value='Infringes my right'>Infringes my rights</option>";
		message += "	<option value='Is considered spam'>Is considered spam</option>";
		message += "	<option value='Is sexually explicit'>Is sexually explicit </option>";
		message += "	<option value='Other'>Other</option>";
		message += "</select>";
		
		Boxy.ask( message, ["OK", "Cancel"], function(response) {
			if(response=="OK"){
				var reason = $("#reason").val();
	
				var data = {
					reason: reason
				}
				
				$.post('/report-abuse.html', data, function(result) {
					var locationReload = false;
					if(result=="success"){
						var title = "Thank you!";
						var message = "Thank you for sharing your concerns. We can only process copyright complaints submitted by authorised parties in accordance with processes defined in law. There may be significant legal penalties for false notices.";
						displaySuccessMessage(title, message);
					}else if(result=="error - invalid parameters"){
						var title = "Ooops...";
						var message = "There seems to be a problem on this functionality. System admin will be notified.";
						displayAttentionMessage(title, message);
					}else if(result=="error - not logged in"){
						var title = "You've got to <a href='/login'>login</a> or <a href='/register'>sign up</a> to AZUDOO to do this";
						var message = "You've got to <a href='/login'>login</a> or <a href='/register'>sign up</a> to AZUDOO to do this";
						displayAttentionMessage(title, message);
					}
				});
			}
		}, {title: title});
	}
}


function sendToFriend(type, id){
	if($("#l").val()==0){
	
		var title = "You've got to login or join AZUDOO to do that";			
		var message = "You will have to login to send this page to your friend. Click here to <a href='/login'>login</a>";
		displayAttentionMessage(title, message);

	}else{
	
		var title = "Send to a friend";
		var message = "To invite someone to check this out, please fill out the form below!<br /><br />";
		message += "To: <br />";
		message += "<input type='text' id='to' value=''> (friend's email address)<br /><br />";
		message += "Message:<br />";
		message += "<textarea id='message' style='width:100%; height:100px;'></textarea>";
		
		Boxy.ask( message, ["OK", "Cancel"], function(response) {
			if(response=="OK"){
				var to = $("#to").val();
				var message = $("#message").val();			
	
				var data = {
					to: to,
					id: id,
					type: type,
					message: message
				}
				
				$.post('/send-to-friend.html', data, function(result) {
					var locationReload = false;
					if(result=="OK" || result=="ok"){
						var title = "Email has been sent!";
						var message = "Email has been sent to your friend. Thank you for using this service";
						displaySuccessMessage(title, message);
					}else if(result=="error - invalid parameters"){
						var title = "Ooops...";
						var message = "There seems to be a problem on this functionality. System admin will be notified.";
						displayAttentionMessage(title, message);
					}else if(result=="error - not logged in"){
						var title = "You've got to login or sign up to AZUDOO to do this";
						var message = "You've got to <a href='/login'>login</a> or <a href='/register'>sign up</a> to AZUDOO to do this";				
						displayAttentionMessage(title, message);
					}
				});
			}
		}, {title: title});
	}
}

function messageMember(type, id, objectTitle){
	if($("#l").val()==0){
	
		var title = "You've got to login or join AZUDOO to do that";			
		var message = "You will have to login to send a message to this person. Click here to <a href='/login'>login</a>";
		displayAttentionMessage(title, message);

	}else{
	
		var title = "Get in touch";
		var message = "<strong>" + objectTitle + "</strong><br /><br />";
		message += "Message:<br />";
		message += "<textarea id='message' style='width:100%; height:100px;'></textarea>";
		
		Boxy.ask( message, ["SEND", "Cancel"], function(response) {
			if(response=="SEND"){
				var message = $("#message").val();			
				var data = {
					id: id,
					type: type,
					message: message
				}
				
				$.post('/send-message.html', data, function(result) {
					var locationReload = false;
					if(result=="OK" || result=="ok"){
						var title = "Message has been sent!";
						var message = "Message has been sent to this member.";
						displaySuccessMessage(title, message);
					}else if(result=="error - invalid parameters"){
						var title = "Ooops...";
						var message = "There seems to be a problem on this functionality. System admin will be notified.";
						displayAttentionMessage(title, message);
					}else if(result=="error - not logged in"){
						var title = "You've got to login or sign up to AZUDOO to do this";
						var message = "You've got to <a href='/login'>login</a> or <a href='/register'>sign up</a> to AZUDOO to do this";				
						displayAttentionMessage(title, message);
					}
				});
			}
		}, {title: title});
	}
}


function changePage(page){
	$("#page").val(page);
	$("#browseForm").submit();
}


function toggleMoreLessText(id){
	if( id != "" ){
		var current = "";
		current = $('#hiddenDescription' + id).css("display");
		// if displayed - show hide option
		if( current=="block" ){
			
			$('#smallDescription' + id).css("display", "block");
			$('#hiddenDescription' + id).css("display", "none");
			$('#moreLessTextImage' + id).attr({
				"src": "/images/expand_static.png",
				"onMouseOver": "this.src='/images/expand_over.png'",
				"onMouseOut": "this.src='/images/expand_static.png'"
			});
		// if hidden - show display option
		}else{
			$('#smallDescription' + id).css("display", "none");			
			$('#hiddenDescription' + id).css("display", "block");	
			$('#moreLessTextImage' + id).attr({
				"src": "/images/contract_static.png",
				"onMouseOver": "this.src='/images/contract_over.png'",
				"onMouseOut": "this.src='/images/contract_static.png'"
			});
		}
	}
}



function copyHomeAddress(){
	if($("#street1").val() == ""){
		$("#street1").val( $("#address1").val() );
		$("#street2").val( $("#address2").val() );
		$("#street3").val( $("#address3").val() );
		$("#street4").val( $("#address4").val() );
		$("#city").val( $("#homeCity").val() );
		$("#state").val( $("#homeState").val() );
		$("#postcode").val( $("#homePostcode").val() );
		$("#country").val( $("#homeCountry").val() );
	}else{
		$("#street1").val( "" );
		$("#street2").val( "" );
		$("#street3").val( "" );
		$("#street4").val( "" );
		$("#city").val( "" );
		$("#state").val( "" );
		$("#postcode").val( "" );
		$("#country").val( "" );		
	}
}

var openCVVInformation = function(type){
	var title = "Security code information";
	var message = "<iframe src='/cvv-information.html?type=" + type + "'></iframe>";
	var data = {
		type: type
	}
	if(type=="amex") title = "Four Digit Card Security Code";
	else title = "Three Digit Card Security Code";

	$.get('/cvv-information.html', data, function(message) {
		Boxy.ask( message, ["CLOSE"], function(response) {
	
		}, {title: title});
	});
}


var openVotingDialog = function(id, title, voteType){
	displayConfirmationForVoting(id, title, voteType);
}



/**
 * Voting box for money
 */
var openVotingMoneyDialog = function(id, ideaTitle, voteType){
	var title = voteType.toUpperCase() + " \"" + ideaTitle + "\"?";
	var message = "Comments:<br />"
	message += "<textarea rows=6 id=\"comment\" style=\"width:100%\" onkeyup=\"limitChars('comment', 140, 'charlimitinfo')\"></textarea>";
	message += "<span class=\"formError\" id=\"charlimitinfo\" style=\"display:block; color:#00A79D; text-align:left;\">Optional</span>";

	if($("#l").val()!=1){
		title = "You've got to login or join AZUDOO to do that";			
		message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
		displayAttentionMessage(title, message);
		return false;
	}		
	Boxy.ask( message, ["OK", "Cancel"], function(response) {
    	if(response=="OK"){
			var comments = $("#comment").val();
			
			if(voteType=="rock") value=1;
			else value=0;

			var data = {
				pitch_id: id,
				value: value,
				comments: comments
			}
			
			$.get('/vote-money.html', data, function(returnedData) {
				var locationReload = false;
				if(returnedData=="success"){
					// display correct icon on the top
					if(value==1){
						$("#personalRock" + id ).html("<img src='/images/icon_rocked.png' />");
					}else{
						$("#personalRoll" + id ).html("<img src='/images/icon_rolled.png' />");
					}
					// get vote count right
					$.get('/check-vote-count.html', {id:id, type:"rock", objectType:"pitch"}, function(rock) {
						if(rock!="error"){
							$.get('/check-vote-count.html', {id:id, type:"roll", objectType:"money"}, function(roll) {
								var net = rock-roll;
								if(net<0){
									$("#rock" + id + "Caption").html("");																									  
									$("#roll" + id + "Caption").html( (net*-1) );
								}else if(net>0){
									$("#rock" + id + "Caption").html( net );																									  
									$("#roll" + id + "Caption").html( "" );
								}else{
									$("#rock" + id + "Caption").html( "0");																									  
									$("#roll" + id + "Caption").html( "0" );							
								}
							});			
						}
					});
					// display message saying vote has been saved
					//$("#message" + id).html("Vote saved");
					$("#rock" + id + "Button, #roll" + id + "Button").unbind("click");
				    //$("#message" + id).fadeOut(10000);					
					displayAttentionMessage("Vote saved", "");
				}else if(returnedData=="not success - have voted"){
					var title = "Unsuccessful voting";			
					var message = "You have voted on this pitch - you are only allowed to vote once for each pitch in a pitch OR money cycle";
					displayAttentionMessage(title, message);
				}else if(returnedData=="not success - non paid member"){
					var title = "Unsuccessful voting";			
					var message = "Unpaid member - you are only allowed to vote for each idea once you have become member of the azudoo mutual. You will have to become a full paid member and logged in. <a href='/register'>Click here to become a member</a><a href='/login'>Click here to login</a>";
					displayAttentionMessage(title, message);
				}else if(returnedData=="not success - not logged in"){
					var title = "You've got to login or join AZUDOO to do that";			
					var message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
					displayAttentionMessage(title, message);
				}
			});
			

	  	}
    }, {title: title});
	return false;
}

/**
 * Voting box for pitch
 */
var openVotingPitchDialog = function(id, ideaTitle, voteType){
	var title = voteType.toUpperCase() + " \"" + ideaTitle + "\"?";
	var message = "Comments:<br />"
	message += "<textarea rows=6 id=\"comment\" style=\"width:100%\" onkeyup=\"limitChars('comment', 140, 'charlimitinfo')\"></textarea>";
	message += "<span class=\"formError\" id=\"charlimitinfo\" style=\"display:block; color:#00A79D; text-align:left;\">Optional</span>";

	if($("#l").val()!=1){
		title = "You've got to login or join AZUDOO to do that";			
		message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
		displayAttentionMessage(title, message);
		return false;
	}		
	
	Boxy.ask( message, ["OK", "Cancel"], function(response) {
    	if(response=="OK"){
			var comments = $("#comment").val();
			
			if(voteType=="rock") value=1;
			else value=0;

			var data = {
				pitch_id: id,
				value: value,
				comments: comments
			}
			
			$.get('/vote-pitch.html', data, function(returnedData) {
				var locationReload = false;
				if(returnedData=="success"){
					// display correct icon on the top
					if(value==1){
						$("#personalRock" + id ).html("<img src='/images/icon_rocked.png' />");
					}else{
						$("#personalRoll" + id ).html("<img src='/images/icon_rolled.png' />");
					}
					// get vote count right
					$.get('/check-vote-count.html', {id:id, type:"rock", objectType:"pitch"}, function(rock) {
						if(rock!="error"){
							$.get('/check-vote-count.html', {id:id, type:"roll", objectType:"pitch"}, function(roll) {
								var net = rock-roll;
								if(net<0){
									$("#rock" + id + "Caption").html("");																									  
									$("#roll" + id + "Caption").html( (net*-1) );
								}else if(net>0){
									$("#rock" + id + "Caption").html( net );																									  
									$("#roll" + id + "Caption").html( "" );
								}else{
									$("#rock" + id + "Caption").html( "0");																									  
									$("#roll" + id + "Caption").html( "0" );							
								}
							});			
						}
					});
					// display message saying vote has been saved
					//$("#message" + id).html("Vote saved");
					$("#rock" + id + "Button, #roll" + id + "Button").unbind("click");
				    //$("#message" + id).fadeOut(10000);	
					displaySuccessMessage("Vote saved", "");
				}else if(returnedData=="not success - have voted"){
					var title = "Unsuccessful voting";			
					var message = "You have voted on this pitch - you are only allowed to vote once for each pitch in a pitch OR money cycle";
					displayAttentionMessage(title, message);
				}else if(returnedData=="not success - non paid member"){
					var title = "Unsuccessful voting";			
					var message = "Unpaid member - you are only allowed to vote for each idea once you have become member of the azudoo mutual. You will have to become a full paid member and logged in.<br /><br /><a href='/register'>Click here to become a member</a><br /><a href='/login'>Click here to login</a>";
					displayAttentionMessage(title, message);
				}else if(returnedData=="not success - not logged in"){
					var title = "You've got to login or join AZUDOO to do that";			
					var message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
					displayAttentionMessage(title, message);
				}
			});
	  	}
    }, {title: title});
    return false;
}


/**
 * Voting box for idea
 */
var displayConfirmationForVoting = function(id, ideaTitle, voteType){
		
	var title = voteType.toUpperCase() + " \"" + ideaTitle + "\"?";
	var message = "<div style='font-size:16px; font-weight:bold; color:#00A79D'>" + ideaTitle + "</div><br /><br />Your additional comment about this idea:<br />"
	message += "<textarea rows=6 id=\"comment\" style=\"width:100%\" onkeyup=\"limitChars('comment', 140, 'charlimitinfo')\"></textarea>";
	message += "<span class=\"formError\" id=\"charlimitinfo\" style=\"display:block; color:#00A79D; text-align:left;\">Optional</span>";
	message += "<br /><span class=\"formError\" id=\"charlimitinfo\" style=\"display:block; color:#00A79D; text-align:left;\">* All comments will appear in the Rock 'n' Roll.</span>";
	
	if($("#l").val()!=1){
		title = "You've got to login or join AZUDOO to do that";			
		message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
		displayAttentionMessage(title, message);
		return false;
	}		
	
	Boxy.ask( message, ["OK", "Cancel"], function(response) {
    	if(response=="OK"){
			var comments = $("#comment").val();

			if(voteType=="rock") value=1;
			else value=0;
			

			var data = {
				idea_id: id,
				value: value,
				comments: comments
			}
			
			$.get('/vote.html', data, function(returnedData) {
				var locationReload = false;
				if(returnedData=="success"){
					// display correct icon on the top
					if(value==1){
						$("#personalRock" + id ).html("<img src='/images/icon_rocked.png' />");
					}else{
						$("#personalRoll" + id ).html("<img src='/images/icon_rolled.png' />");
					}
					// get vote count right
					$.get('/check-vote-count.html', {id:id, type:"rock", objectType:"idea"}, function(rock) {
						if(rock!="error"){
							$.get('/check-vote-count.html', {id:id, type:"roll", objectType:"idea"}, function(roll) {
								var net = rock-roll;
								if(net<0){
									$("#rock" + id + "Caption").html("");																									  
									$("#roll" + id + "Caption").html( (net*-1) );
								}else if(net>0){
									$("#rock" + id + "Caption").html( net );																									  
									$("#roll" + id + "Caption").html( "" );
								}else{
									$("#rock" + id + "Caption").html( "0");																									  
									$("#roll" + id + "Caption").html( "0" );							
								}
							});			
						}
					});
					// display message saying vote has been saved
					//$("#message" + id).html("Vote saved");
					$("#rock" + id + "Button, #roll" + id + "Button").unbind("click");
				    //$("#message" + id).fadeOut(10000);		
					displaySuccessMessage("vote saved", "You have voted " + voteType + " on '" + ideaTitle + "' project.");
				}else if(returnedData=="not success - have voted"){
					var title = "Unsuccessful voting";			
					var message = "You have voted on this idea - you are only allowed to vote once for each idea";
					displayErrorMessage(title, message);
				}else if(returnedData=="not success - non paid member"){
					var title = "Unsuccessful voting";			
					var message = "Unpaid member - you are only allowed to vote for each idea once you have become member of the azudoo mutual. You will have to become a full paid member and logged in.<br /><br /><a href='/register'>Click here to become a member</a><br /><a href='/login'>Click here to login</a>";
					displayAttentionMessage(title, message);
				}else if(returnedData=="not success - not logged in"){
					var title = "You've got to login or join AZUDOO to do that";			
					var message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
					displayAttentionMessage(title, message);
				}
			});
	  	}
    }, {title: title});

    return false;
}



function toggle(id){
	current = $("#" + id).css("display"); 
 	if( current=="block" ){
  		$('#' + id).css("display", "none");
//		$('#' + id).slideOut(1000);
 	}else{
  		$('#' + id).css("display", "block");
//		$('#' + id).slideIn(1000);
 	}
}

function addslashes(str) {
	str=str.replace(/\'/g,'\'');
	str=str.replace(/\"/g,'\"');
	str=str.replace(/\\/g,'\\');
	//str=str.replace(/\0/g,'\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			
			if (c_end==-1) 	c_end=document.cookie.length;
			
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
function isEmail(string) {
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	var result=emailfilter.test(string);
	return result;
}               

function isProper(string) {
   if (!string) return false;
   var iChars = "!\"£$%^&*()+=`':;~#/?.>,<|\\/";
   
   for (var i = 0; i < string.length; i++) {
	  if (iChars.indexOf(string.charAt(i)) != -1) return false;
   }
   return true;
} 


function editMessage(id, ideaTitle, object){
	$.get('/get-small-description.html', {object_id:id, object_type: object}, function(smallDescription) {
		var title = ideaTitle;
		var message = "<textarea rows=6 id=\"smallDescription\" style=\"width:100%\" onkeyup=\"limitChars('smallDescription', 140, 'charlimitinfo')\">" + smallDescription + "</textarea>";
		message += "<span class=\"formError\" id=\"charlimitinfo\" style=\"display:block; color:#00A79D; text-align:left;\">Optional</span>";
		message += "<br /><span class=\"formError\" id=\"charlimitinfo\" style=\"display:block; color:#00A79D; text-align:left;\">* All comments will appear in the Rock 'n' Roll.</span>";
	
		if($("#l").val()==0){
			title = "You've got to login or join AZUDOO to do that";			
			message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
			displayAttentionMessage(title, message);
			return false;
		}		
		
		Boxy.ask( message, ["UPDATE", "Cancel"], function(response) {
			if(response=="UPDATE"){
				var smallDescription = $("#smallDescription").val();
				var data = {
					object_id:id, 
					object_type: object,
					smallDescription: smallDescription
				}
				$.get('/update-small-description.html', data, function(returnedData) {
					var locationReload = false;
					if(returnedData=="success"){
						$("#shortDescription").html(smallDescription);
						displaySuccessMessage("status has been updated", "");
						return false;
					}else if(returnedData=="not success"){
						var title = "You've got to login or join AZUDOO to do that";			
						var message = "You will have to become a paid member and login to vote. <a href='/register'>Click here to become a member</a> and <a href='/login'>login</a>";
						//Boxy.alert(message, function(){ if(locationReload) location.reload(true); }, {title: title}, "OK");					
						displayAttentionMessage(title, message);
					}
					return false;
				});
			}
			return false;
		}, {title: title});
		return false;
	});
	return false;
}

function showWeeklyCycleInfo(){
	$.get('/weekly-cycle-info.html', "", function(content) {
		var title = "You are looking at the time left in AZUDOO's<br />weekly cycle.";
		var message = content;
		//ajax call
		Boxy.alert(message, function(){ }, {title: title}, "OK");
	});
}

function displayVideoIntroduction(){
	var message = '<object width="480" height="480"><param name="movie" value="http://www.youtube.com/v/qiP79vYsfbo&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/qiP79vYsfbo&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="360"></embed></object>';	
	Boxy.alert(message, function(){ return false;}, {title: "AZUDOO"}, "CLOSE");
}

function displayAzudooIntroduction(){
	$.get('/weekly-cycle-info.html?intro=1', "", function(content) {
		var title = "What is AZUDOO?";
		var message = content;
		//ajax call
		Boxy.alert(message, function(){ }, {title: title}, "OK");
	});
}

function togglePageTips(){
	toggle('helper_bar_default'); 
	toggle('helper_bar_content'); 
}
function displayErrorMessage(title, message){
	$('#colored-error').show();
	$("#helper_bar_content").hide();	
	$("#helper_bar_default").show();
	$("#error_bar").stop();
	$("#error_bar").html(message);
	$("#error_bar").fadeIn(1000, function(){
		setTimeout('$("#error_bar").fadeOut(1000);', 5000);											 
		//if( mouseY > screen.height ){
			$(window).scroll(function(){
			$('.colored-notification-bar').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 150});  
			if( $(window).scrollTop() < 77 ){
					$('.colored-notification-bar').animate(
						{top:"77px" },
						{queue: false, duration: 250}, 
						"", 
						function(){
							setTimeout('$("#error_bar").fadeOut(1000);', 2000);											 
						}
					);  
				}else{
					$('.colored-notification-bar').animate(
						{top:$(window).scrollTop()+"px" },
						{queue: false, duration: 250}, 
						"", 
						function(){
							setTimeout('$("#error_bar").fadeOut(1000);', 2000);											 
						}
					);  
				}
			});
		//}
	});
}

function displaySuccessMessage(title, message){
	$('#colored-success').show();
	$("#helper_bar_content").hide();	
	$("#helper_bar_default").show();
	$("#success_bar").stop();
	$("#success_bar").html(message);
	$("#success_bar").fadeIn(1000, function(){
		setTimeout('$("#success_bar").fadeOut(1000);', 5000);											 
		//if( mouseY > screen.height ){
			  
			$(window).scroll(function(){
				$('.colored-notification-bar').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 150});
				if( $(window).scrollTop() < 77 ){
					$('.colored-notification-bar').animate(
						{top:"77px" },
						{queue: false, duration: 250}, 
						"", 
						function(){
							setTimeout('$("#success_bar").fadeOut(1000);', 2000);											 
						}
					);  
				}else{
					$('.colored-notification-bar').animate(
						{top:$(window).scrollTop()+"px" },
						{queue: false, duration: 250}, 
						"", 
						function(){
							setTimeout('$("#success_bar").fadeOut(1000);', 2000);											 
						}
					);  
				}
			});
		//}
	});
}

function displayAttentionMessage(title, message){
	$('#colored-notification').show();
	$("#helper_bar_content").hide();	
	$("#helper_bar_default").show();
	$("#notification_bar").stop();
	$("#notification_bar").html(message);
	$("#notification_bar").fadeIn(1000, function(){
		setTimeout('$("#notification_bar").fadeOut(1000);', 10000);											 
		//if( mouseY > screen.height ){
		$(window).scroll(function(){
				$('.colored-notification-bar').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 150});
				if( $(window).scrollTop() < 77 ){
					$('.colored-notification-bar').animate(
						{top:"77px" },
						{queue: false, duration: 250}, 
						"", 
						function(){
							setTimeout('$("#notification_bar").fadeOut(1000);', 2000);											 
						}
					);  
				}else{
					$('.colored-notification-bar').animate(
						{top:$(window).scrollTop()+"px" },
						{queue: false, duration: 250}, 
						"", 
						function(){
							setTimeout('$("#notification_bar").fadeOut(1000);', 2000);											 
						}
					);  
				}
			});
		//}
	});
}

function blank(){}


var mouseX = 0;
var mouseY = 0;
$(document).bind("click", getMousePosition);
function getMousePosition(e){
    if (e.pageX == null){
       // IE case
       var d = (document.documentElement && 
               document.documentElement.scrollLeft != null) ?
              document.documentElement : document.body;
       mouseX = e.clientX + d.scrollLeft;
       mouseY = e.clientY + d.scrollTop;
    }else{
       // all other browsers
       mouseX = e.pageX;
       mouseY = e.pageY;
    }

}

var openSubscribeIdeaDialog = function(id, title, type){
 	displaySubcribeDialog(id, title, type);
	return false;
}

var displaySubcribeDialog = function(id, title, type){

	if($("#l").val()==0){
	
		title = "You've got to login or join AZUDOO to do that";			
		message = "You will have to login to support a project. Click here to <a href='/login'>login</a>";
		displayAttentionMessage(title, message);

	}else{
	
		if(type==1){
			title = "Support \" " + title + " \"?";
			message = ""	
		}else{
			title = "Leave \" " + title + " \"?";
			message = ""			
		}
		Boxy.ask( message, ["Yes", "No"], function(response) {
			if(response=="Yes"){
				var data = {idea_id: id	};
				$.get('/subscribe-idea.html', data, function(returnedData) {
					if(returnedData=="success"){
						if(type==1){
							title = "Congratulation!";
							message = "You are supporting this project! You will see all details on your dashboard";
							displaySuccessMessage(title, message);
						}else{
							title = "Congratulation!";
							message = "You are now unsupporting this project. Feel free to re-subscribe!";
							displaySuccessMessage(title, message);
						}					
					}else if(returnedData=="not success - not logged in"){
						title = "You've got to login or join AZUDOO to do that";			
						message = "You are not allowed to support on this project. You will have to become a free-member or paid member and login.";
						displayAttentionMessage(title, message);
					}
				});
			}
		}, {title: title});
	}
}

// do image preload
if (document.images){
	var imgPreload = new Image();
	var ImageUrl = new Array();
	ImageUrl[0] = "/images/button_roll_o.png";
	ImageUrl[1] = "/images/button_rock_o.png";
	ImageUrl[2] = "/images/button_rock.png";
	ImageUrl[3] = "/images/button_roll.png";	  
	ImageUrl[4] = "/images/icon_profile_roll.png";	  
	ImageUrl[5] = "/images/icon_profile_rock.png";	  
	ImageUrl[6] = "/images/expand_static.png";	  
	ImageUrl[7] = "/images/expand_over.png";	  	  
	ImageUrl[8] = "/images/contract_over.png";	  
	ImageUrl[9] = "/images/contract_static.png";	  	  
	for(var i = 0; i <= 9; i++){
		imgPreload.src = ImageUrl[i];
	}
	
}


$(document).ready(function(){

	// restyle the button
	$('#container [type=submit]').addClass('button');
	$('#container [type=reset]').addClass('button');
	$('#container [type=button]').addClass('button');
	$('#container [type=password]').addClass('inputText');	
	$('#container [type=text]').addClass('inputText');	
	$('#container [type=file]').addClass('inputText');		
	$('#container textarea').addClass('inputText');
	$('#container select').addClass('dropDown');
	$('#container [type=text], #container [type=password], #container textarea').bind('focus', function(){
		$(this).addClass("inputTextSelected");
	});		
	$('#container [type=text], #container [type=password], #container textarea').bind('blur', function(){
		$(this).removeClass("inputTextSelected");
	});		
	$('#container [type=submit], #container [type=button]').bind('mouseenter', function(){
		$(this).addClass("hover");
	});		
	$('#container [type=submit], #container [type=button]').bind('mouseleave', function(){
		$(this).removeClass("hover");
	});		

	// make the expand graphic defaulted to where the user are
	$('.moreLessTextImage').attr({
		"src": "/images/expand_static.png",
		"onMouseOver": "this.src='/images/expand_over.png'",
		"onMouseOut": "this.src='/images/expand_static.png'"
	});
	
	// /* first & last element/
	$('.discussion_topic:last').addClass("last_element");
	$('.discussion_topic:first').addClass("first_element");

	$('.feed-item:last').addClass("last_element");
	$('.feed-item:first').addClass("first_element");

	$('.detail_main_content div:last').addClass("last_element");
	$('.detail_main_content div:first').addClass("first_element");

	$('.member_avatar_listing:last').addClass("last_element");
	$('.member_avatar_listing:first').addClass("first_element");

	$('.ideaVoteComment:last').addClass("last_element");
	$('.ideaVoteComment:first').addClass("first_element");

	$('#idea .listing:last').addClass("last_element");
	$('#idea .listing:first').addClass("first_element");

	$('#pitch .listing:last').addClass("last_element");
	$('#pitch .listing:first').addClass("first_element");
	
	$('#money .listing:last').addClass("last_element");
	$('#money .listing:first').addClass("first_element");

	$('#idea .dashboard-wrap:last').addClass("last_element");
	$('#idea .dashboard-wrap:first').addClass("first_element");

	$('#pitch .dashboard-wrap:last').addClass("last_element");
	$('#pitch .dashboard-wrap:first').addClass("first_element");
	
	$('#money .dashboard-wrap:last').addClass("last_element");
	$('#money .dashboard-wrap:first').addClass("first_element");

	$('.blog:last').addClass("last_post");

	$('.formRequired').html(" *");
	
	//* legal information/
	$("#sidebar a").bind("mouseover", function(){
		$(this).parent().addClass("mouseOver");
	});
	$("#sidebar a").bind("mouseout", function(){
		$(this).parent().removeClass("mouseOver");
	});		
			
	//$(".listing td .expand-icon-container").css('display','none');
	//$(".listing td .expand-icon-container").hide();
	

	$(".listing").hover(
		function(){
			$(this).css("background-color", "#EBECED");
			$(this).find("td .expand-icon-container").show();
		},
		function(){
			$(this).css("background-color", "#ffffff");
			$(this).find("td .expand-icon-container").hide();
		}		
	);		

});

	$(document).ready(function(){
		if(BrowserDetect.browser=="Explorer" && BrowserDetect.version=="6"){
			$('.rockRollContainer').pngFix();
			$('#helper_bar').pngFix();			
			$('.ideaVoteComment').pngFix();						
			$('.share-social-networking').pngFix();						
			//$('#menu').pngFix();
		}
    });