/*
*/




(function($){$.fn.growing=function(options){var settings=$.extend({maxHeight:200,minHeight:40,buffer:0},options);return this.each(function(){var textarea=$(this);var minh=textarea.height()>settings.minHeight?textarea.height():settings.minHeight;var w=parseInt(textarea.width()||textarea.css("width"));var div=$("<div class='faketextarea' style='position:absolute;left:-10000px;width:"+w+"px;'></div>");textarea.after(div);var resizeBox=function(){var html=textarea.val().replace(/(<|>)/g,'').replace(/\n/g,"<br>|");if(html!=div.html()){div.html(html);var h=div.height();prevh=textarea.height();var newh=h<=minh?minh:(h>settings.maxHeight?settings.maxHeight:h);newh+=settings.buffer;if(newh>=settings.maxHeight){textarea.css("overflow","auto")}else{textarea.css("overflow","hidden")}textarea.css({"height":newh+"px"})}};textarea.keydown(resizeBox);textarea.keyup(resizeBox);resizeBox()})}})(jQuery);
(function($){$.fn.ghostText=function(){return this.each(function(){var text=$(this).attr("title");if(text!=""&&($(this).val()==""||$(this).val()==text)){$(this).addClass("disabled");$(this).val(text);$(this).focus(function(){$(this).removeClass("disabled");if($(this).val()==text){$(this).val("")}});$(this).blur(function(){if($(this).val()==""){$(this).val(text);$(this).addClass("disabled")}})}})}})(jQuery)








// Doms Shiz
$(document).ready(function(){	

   
$('#birthday_month').change(function(){drop_date_month_change(this, 'birthday_day', 'birthday_year')});
$('#birthday_year').change(function(){drop_date_year_change('birthday_month', 'birthday_day', 'birthday_year')});
	
						   

// homepage stuff //



$("#home #step1").click(function () {
  $("h1, #slider, #controls").remove();
  $('#signup_fieldset').fadeIn(1000);
  $('#left').html("<ul class='about_jolly'><li class='store'><strong><span>Store</span> your memories</strong> <small>Access your photos, videos, stories and friends – anytime, anywhere.</small></li><li class='share'><strong><span>Share</span> your experiences</strong> <small>Start an online collection of all your Jollys and see where other people have been too!</small></li><li class='inspire norule'><strong><span>Inspire</span> others</strong> <small>Sign-up now to inspire our community with your latest Jollys – Where've you been?</small></li></ul><div class='quote'><span class='em'>Are you a hardened traveller, day-tripper or all round fun-haver? Sign up now to store, share and inspire! <a title='Find out more...' href='/about/'>find out more</a></span></div>");
  $('#home #step1').parent().insertAfter($('.error'));
  $('#home #step1').parent().html("<button value='Create my account' name='signup' type='submit'>Create my account</button>");
  $('body').attr("id","signup");
  $(".nav-signup").append("<div></div>"); // sort nasty ie 6 bug
  return false;
});


// end of Homepage //


// showmore of the Trimmed Paragraph


$('.more').live("click", function (){								   
$(this).next("span").show();	
$(this).hide();									   
});


// show Jolly Map

$("button[name='view_jolly_map']").live("click", function (){
vid = $(this).attr('id').replace("jollymap_", '');	

var mapHTML 
mapHTML =	"<div id='map_container' style='width:640px; height:420px;'><div id='map'>" +
			"<div class='noFlash'>"+
			"<p><strong>Upgrade your Flash&#8482; player</strong>This content requires a more recent version of the Flash&#8482; plugin. <br />This plugin is free! <a href='http://www.adobe.com/products/flashplayer/'>Download  it now!</a>.</p>"+
			"</div>"+
			"</div></div>"+
			"<div class='inline_footer'>" +
			"<select class='select' id='mappingProvider' name='mappingProvider'>" +
			"<option selected='selected' value='G'>Google Maps</option>" +
			"<option value='Y'>Yahoo Maps</option>" +
			"<option value='M'>Microsoft Bing Maps</option>" +
			"<option value='O'>OpenStreetMap</option>" +
			"</select>" +
			"<button name='close' class='button_sprite ui_button' type='button' title='Close window' onclick='Boxy.get(this).hide();'><img alt='' src='/img/spacer.gif' class='close'><span>Close window</span></button>" +
			"</div>",

new Boxy(mapHTML,{modal: true, afterShow:function(){map(vid);}});
return false;										   
});	







$('#mappingProvider').live('change', function() {
  // Live handler called.
dom = $(this).val()
map(vid,dom)
});


// Share Toggle //

$("#MediaEmbed").toggle(
  function () {
    $('#MediaEmbedCode').fadeIn();
	$.scrollTo($('#embed_code'), 1000);
	 $('.embedCode').text("Hide Embed Code");
  },
  function () {
    $('#MediaEmbedCode').fadeOut()
	$('.embedCode').text("Place on your website");
  }
);

//


// Signup stuff //
// :: Check username  ::
$('#username').blur(function() {
    var text = $('#username').val();
    var textlength = text.length;
    if (textlength >= 5) {
      $('#username').addClass('input_loading');
      $.post("/apps/common/check_username.asp", {username: $('#username').val()},
      function(response) {
        $('#usernameResult').fadeOut();
        setTimeout("finishUsernameCheck('usernameResult', '" + escape(response) + "')", 400);
      });
    }
    return false;
  });







function done() {
alert("Signed Up")
}

$(document).ready(function () {
  jQuery("#signup_form").validate({
	onkeyup: false,
    errorContainer: "#signup_form_errorbox",
    errorLabelContainer: "#signup_form_errorbox ul",
    wrapper: "li",
rules: {
      username: {
        required: true,
        rangelength: [5, 18]
      },
      password: {
        required: true,
        rangelength: [3, 20]
      },
      birthday_day: {
        range: [1, 31]
      },
      birthday_month: {
        range: [1, 12]
      },
      birthday_year: {
        range: [1900, 1996]
      },
      email: {
        required: true,
        email: true
      },
      invitecode: {
        required: true
      }
    },
    messages: {
      username: {
        required: "Enter a username",
        rangelength: "Username must be 5 - 18 characters"
      },
      password: {
        required: "Enter a password",
        rangelength: "Password must be 3 - 20 characters"
      },
      birthday_day: {
        range: "Enter your day of birth"
      },
      birthday_month: {
        range: "Enter your month of birth"
      },
      birthday_year: {
        range: "Enter your year of birth"
      },
      email: "Enter your valid e-mail Address",
      invitecode: "Enter a valid Invite Code"
    },
    submitHandler: function (form) {
      jQuery(form).ajaxSubmit({
        target: '#right',
        success: done,
        resetForm: true
      });
    }
  });
});

// end of Signup //





/*
        success: function (data) {
			// Ajax Success
          if (data.indexOf("ajax-success") != -1) {
			window.location.replace("/login/?info=REG_ACTIVATE");
          } else if (data.indexOf("error") != -1) {
            // Ajax Error
            $('.error').remove();
            $('.call_to_action').before(data);
            $(handler).unblock();
          } else {}
        },
        error: function () {
			$(handler).unblock();
          alert("Please try again, a server error occurred");
        }
      });
    }
  });
  
  */

						   
						   
						   
       						   
						   
						   
						   




$('a[rel=boxy]').boxy();


$('a[rel=boxy_modal]').live("click", function(e){
	Boxy.load($(this).attr('href'),{filter:".boxyMe", title:$(this).attr('title'),modal: true})
	e.preventDefault();
});
	
$('a[rel=boxy_contact]').live("click", function(e){
	Boxy.load($(this).attr('href'),{filter:".boxyMe", title:$(this).attr('title'),modal: true,afterShow:function(){contactForm();}})
	e.preventDefault();
});	


$('a[rel=boxy_report]').live("click", function(e){
	Boxy.load($(this).attr('href'),{filter:".boxyMe", title:$(this).attr('title'),modal: true,afterShow:function(){
				
		$('.boxyMe button').wrap('<div class="inline_footer m20t" />');	
		$('.go').before("<button value='Submit' class='close m10l' name='submit' type='submit' onclick='Boxy.get(this).hide();'>Cancel</button>")
		reportMedia();
		}})
	e.preventDefault();
});	











$('textarea.inputtextarea').growing();
$(".ghost_text").ghostText();




$('a[rel=tipsy]').tipsy({gravity: 's'});


// check to see what section the tabs are in in the profile page (Nicey Bookmarking)
var pathname=window.location.hash;if(pathname=='#news'){myNews()}else if(pathname=='#about'){myAbout()}else if(pathname=='#summary'){mySummary()};

// Mouseover events for the main navigation
$('#nav ul li').mouseenter(function(){$(this).addClass("over")});$('#nav ul li').mouseleave(function(){$(this).removeClass("over")});

//Click Menu interaction (Quick login)
$(".signin").click(function(e){
e.preventDefault();
$("#signin_menu_panel").show();
$(this).addClass("menu-open")
$(this).appendTo('#signin_menu_panel'); 
});

$("#signin_menu_panel").mouseup(function(){return false});
$(document).mouseup(function(e){
if($('.signin').hasClass('menu-open')){
$(".signin").removeClass("menu-open");
$(".signin").appendTo('.nav-login');
$("#signin_menu_panel").hide();
$(".nav-login").removeClass("over");
}
});


//Click Menu interaction (Account options)
$(".account").click(function(e){
e.preventDefault();
$("#account_menu_panel").show();
$(this).addClass("menu-open")
$(this).appendTo('#account_menu_panel'); 
});

$("#account_menu_panel").mouseup(function(){return false});
$(document).mouseup(function(e){
if($('.account').hasClass('menu-open')){
$(".account").removeClass("menu-open");
$(".account").appendTo('.nav-account');
$("#account_menu_panel").hide();
$(".nav-account").removeClass("over");
}
});


/*
// google translation
$.translate(function () { //when the Google Language API is loaded 
function translateTo(destLang) { //this can be declared in the global scope too if you need it somewhere else 
    $('body').translate('english', destLang, { //translate from english to the selected language 
      not: '#signoff',
      fromOriginal: true //always translate from english (even after the page has been translated) 
    });
  }
  $('#langsel').change(function () {
    translateTo($(this).val());
    // set a cookie to remember the selected language 
	$.cookie('destLang', $(this).val(),{path:'/'});
    return false; //prevent default browser action 
  });
  var destLang = $.cookie('destLang'); //get previously translated language 
  // if destLang IS NOT English Translate
  if (destLang != "en") {
    translateTo(destLang);
  }
}); 
//end of Google Language API loaded 
*/










//function(){alert("Yo")}



//



// Follow Scroll the RH Column
//$('#content_container_wrapper #right').wrapInner("<div id='follow'></div>");
//$('#follow').scrollFollow({speed: 500,offset: 30,container: 'right'});
// End Follow Scroll




// Autosuggest user search
//$('#userid').attr({value:""});
//function findValueCallback(event,data,formatted){$("<li>").html(!data?"No results found":"Selected: "+formatted).appendTo("#result")}
//function formatItem(row){return row[0]+" (<strong>id: "+row[1]+"</strong>)"}
//function formatResult(row){var regexp=/<p[^>]*>(.*?)<\/p>|(<.+?>)/gi;return row[0].replace(regexp,'');}
//$("#user_search_inputtext").autocomplete('/apps/search/ajax_user_suggest.asp',{width:230,scrollHeight:220,delay:600,multiple:false,matchContains:false,minChars:3,formatResult:formatResult});$("#user_search_inputtext").result(findValueCallback).next().click(function(){$(this).prev().search()});$("#user_search_inputtext").result(function(event,data,formatted){var hidden=$('#userid');hidden.val(data[1])});$("#user_search_inputtext").keyup(function(){if($('#user_search_inputtext').val()==""){$('#userid').attr({value:""})}});

// loggedin photo edit
$('#user_photo').mouseover(function () {
  $('#update_profile_image').removeClass("hide").addClass("edit_profile_image_box");
});
$('#user_photo').mouseout(function () {
  $('#update_profile_image').removeClass("edit_profile_image_box").addClass("hide");
});









// User Summary click on Profile

$('#user_summary a').click(function () {
mySummary();
});

$('#user_news a').click(function (){
myNews();
});

$('#user_about a').click(function () {
myAbout();
});






// Ajax News Feed on the users profile
$('#more_news').live("click", function () {

  var uid, pageno
  uid = $(this).attr('class').replace("user", '');
  pageno = $('#more_news a').attr('rel');

  $.ajax({
    url: "/apps/profile/ajax_newsfeed.asp",
    data: "uid=" + uid + "&pageno=" + pageno + "",
    beforeSend: function () {
		$('#more_news').block();
    },
    success: function (html) {
      $('#more_news').remove();
      $('#newsfeed').append(html);
    },
    error: function () {
      $('#more_news').unblock();
      alert("Please try again, a server error occurred");
    }
  });
  return false;
});


/// toggle the newsfeed display

$('#newsfeed .toggle_view').toggle(
function () {
  $(this).addClass("compact");
  $("#newsfeed").addClass("compact");

},
function () {
  $(this).removeClass("compact");
  $("#newsfeed").removeClass("compact");
});


/// toggle the newsfeed display

$('#more_about').toggle(
function () {
	

	$('#more_about span').text('Less');
	$('.about_summary li').addClass('show');
	
	


	
	

	


},
function () {



$('.about_summary li').removeClass('show');
$('#more_about span').text('More');
//$('.about_summary li:last').removeClass('hide')


});



/////////// WIP



$('.show_more').click(function () {
  var handler = $(this);
  var vid = $(handler).closest("div").children(".vid").val();
  var did = $(handler).closest("div").children(".did").val();
  var offset = $(handler).closest("div").children(".max").attr('name').replace(/[a-zA-Z_\s]/g, '');
  var maxphotos = $(handler).closest("div").children(".max").val();
  var media = $('body').attr('class');
  appFolder = media.substring(0, media.length - 1);
  $.ajax({
    url: "/apps/" + appFolder + "/ajax_" + media + ".asp",
    data: "vid=" + vid + "&did=" + did + "&offset=" + offset + "",
    beforeSend: function () {},
    success: function (html) {
      $.scrollTo($('#destination_' + did + ' li:last').after(html), 1000);
      offset++;
      $(handler).closest("div").children(".max").attr('name', 'offset_' + offset);
      if (parseInt($('ul#destination_' + did + ' li').size(), 10) >= maxphotos) {
        $(handler).closest("div").remove();
      }
    },
    error: function () {
      alert("Please try again, a server error occurred");
    }
  });
  return false;
});


//make_friend
//fan_to_friend
//friend_to_fan


$('a[rel*=make_friend]').click(function () {
  var rnd=Math.floor(Math.random()*1000)								
  theUrl = $(this).attr('href');
  handler = $(this);
  boxyTitle = $(this).text();
  $.ajax({
    url: theUrl,
    data: "ajax=1&rnd="+rnd+"",
    beforeSend: function () {
		
		
      $(handler).block();
    },
    success: function (data) {
       if (data == 'denied') {
         $(handler).unblock();
        } 
		else if (data == 'Already Connected') {
         $(handler).unblock();
       
	   
	   
	    } 
		else {
			
		var setContent = null;
      	setContent = new Boxy.load(theUrl, {
        title: boxyTitle+" ?",
        filter: ".boxyMe",
        afterShow: function () {
        friendAdd(boxyTitle);
        }
      });
    //   $(handler).unblock();
       }
    },
    error: function () {
      alert("Please try again, a server error occurred");
    }
  });
  return false;
});




$('a[rel*=friend_to_fan]').click(function () {
  theUrl = $(this).attr('href');
  username = $(this).attr('name');
  tags = 'Are you sure you want to downgrade ' + username + ' to a fan?';
  $.prompt(tags, {
    buttons: {
      "Yes Downgrade": true,
      "Cancel": false
    },
    callback: function (yes) {
      if (yes) {
        $.ajax({
          url: theUrl,
          data: "ajax=1",
          success: function (html) {
            $('#friendstatus').html("<p><span><strong>" + username + "</strong> is now your fan.</span></p>");
            $('#friendstatus p span').effect("highlight", {},5000);
          },
          error: function () {
            alert("Please try again, a server error occurred");
          }
        });
      }
    }
  });
  return false;
});


$('a[rel*=fan_to_friend]').click(function () {
  theUrl = $(this).attr('href');
  username = $(this).attr('name');
  tags = 'Are you sure you want to upgrade ' + username + ' to a friend?';
  $.prompt(tags, {
    buttons: {
      "Yes Upgrade": true,
      "Cancel": false
    },
    callback: function (yes) {
      if (yes) {
        $.ajax({
          url: theUrl,
          data: "ajax=1",
          success: function (html) {
            $('#friendstatus').html("<p><span><strong>" + username + "</strong> is now your friend.</span></p>");
            $('#friendstatus p span').effect("highlight", {},5000);
          },
          error: function () {
            alert("Please try again, a server error occurred");
          }
        });
      }
    }
  });
  return false;
});



/*More Featured jollys*/	
$('#more_jollys, #more_jollys a').click(function () {
$('#more_jollys').hide();
$('#feature_jollys ul li:gt(5)').fadeIn();
$('#feature_jollys ul li:gt(3)').removeClass("norule");
$('#feature_jollys ul li:gt(7)').addClass("norule");
$('#feature_jollys').css({height:"667px"});
$('#explore_wrapper').css({paddingBottom:"717px"});
return false;
});


/*More Tweets jollys*/	
$('#more_tweets').click(function () {
$('.twitter li:gt(2)').fadeIn();
$(this).hide();
return false;
});









				   






















	

	




/*Rating Function*/









/// this is where we are up to with everything cleaned


$("#privacy").toggle(
  function () {
	 $(this).text("These photos will be private");
	 $('#privacy_level').attr("value","1");
  },
  function () {
	$(this).text("These photos will be public");
	$('#privacy_level').attr("value","0");
  }
);


/// show hide comments

//


    $("#comments_toggle").live("click", function () {
     if($("#comments_toggle").hasClass('open')){
		$('#ajax_comments ol').slideUp();
		//$('#ajax_comments .pagination .pagistatus').fadeOut();
		
		
		
		
		
		$("#comments_toggle").removeClass('open');
		$("#comments_toggle").addClass('collapse');
	 }
	 else{
 		$('#ajax_comments ol').slideDown();
		//$('#ajax_comments .pagination .pagistatus').fadeIn();
		$("#comments_toggle").addClass('open');
		$("#comments_toggle").removeClass('collapse');
	 }
    });














//function to check for missing images
//####
//$('img').error(function(){
//var thelink = "/img/user_small.jpg";
//$(this).attr('src', '' + thelink + '');
//});
///###


   $(".footer_pagination a").live("click", function (e) {
	   
	   
	   media = $(this).parent().attr('id').replace(/[0-9]/g, '');
		mediaId = $(this).parent().attr('id').replace(/[a-zA-Z_\s]/g, '');
	   offset = $(this).attr('rel');
	   
	   userId = $('#media_wrapper').attr('class').split(" ");	


	   loadMediaComments(mediaId,media,offset,userId[1]);
	   $.scrollTo($('#comments ol li:first'),1000);
	   e.preventDefault();
	   })

});
/// end of jquery



//



//form button interaction 


$("#commentForm #theComment").live("focus", function(e){
$("#commentForm button").removeClass('hide').addClass('show');
});	


$('#commentForm .comments_notloggedin').live("focus", function(e){
$('#commentForm .alert').addClass("show").show();
$('#commentForm #theComment').hide();
});	






function Comments(id,type){
$.ajax({
   url: "/apps/comment/ajax_comment.asp",
   data: "id="+id+"&type="+type+"",
   success: function(html){
		$("#ajax_comments").html(html);
   }
 });
}




///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





function loadMediaComments(mediaId,mediaType,privacy,postId) {
	
if (privacy == "can") {
	dombo = "<div id='commentForm_errorbox' class='error_container hide m10b'><ul><li class='alert'><strong>There are errors in your form:</strong></li></ul></div><input type='hidden' name='insert' value='comment' /><input type='hidden' name='mediaId' value='"+mediaId+"' /><input type='hidden' name='mediaType' value='"+mediaType+"' /><input type='hidden' name='postId' value='"+postId+"' /><textarea title='Write a comment...' class='inputtextarea comments' id='theComment' rows='6' cols='38' name='comment'></textarea><span id='counter'></span><button class='button_sprite ui_button m10t clearfix fl hide' value='Submit' type='submit'><img class='plus' src='/img/spacer.gif' alt='' />Submit comment</button>"
	$('#commentForm fieldset').html(dombo);
   } 
else if (privacy == "cant") {
dombo = "must be friends"
$('#commentForm fieldset').html(dombo);
   }
else {
	dombo = "<div class='alert big'><p><a class='facebook_connect fr' href='#'>Connect with Facebook</a><strong>Ahoy! </strong><a href='/login/'>Sign In</a> or <a href='/signup/'>Sign Up</a> now to post a comment!</p></div><textarea title='Write a comment...' class='inputtextarea comments_notloggedin' id='theComment' rows='6' cols='38' name='comment'></textarea>"
$('#commentForm fieldset').html(dombo);
}


}





function reportMedia(){
	
var handler = $('.boxy-wrapper #report_form');	
$(handler).validate({
submitHandler: function(form) {
	
media = escape($('#contact_type').val());
id = escape($('#contact_name').val());
reason = escape($('#contact_email').val());

$.ajax({
  type: "POST",
  url: "/contact/report/",
  data: "ajax=1&media=" + media + "&id=" + id +"&reason=" + reason + "",
  beforeSend: function() {
	//$(handler).block();
	//$('.error').remove();
	//alert("Hi")
  },
  success: function(data) {
	// Ajax Success
	if (data.indexOf("ajax-success") != -1) {	
	$('.boxyMe').html("<h2>Thank you</h2><p class='m20b'>For reporting this piece of content. <br/>We will look into this as soon as we can.</p>")
	setTimeout(function(){Boxy.get('.boxyMe').hide();},3500);	
}
	else {
	  $(handler).unblock();
	  //check to see if error is present
	  if($('#report_form .error').length > 0) {
   $('#report_form .error').replaceWith(data);
}else{
	
    $('.boxy-wrapper .inline_footer').before(data);
    return;
}


	  
	}
  },
  error: function() {
	$(handler).unblock();
	alert("Please try again, a server error occurred");
  }
});
}
});

}




function contactForm(){
	
var handler = $('.boxy-wrapper #contact_form');	
$(handler).validate({
submitHandler: function(form) {
contact_type = escape($('#contact_type').val());
contact_name = escape($('#contact_name').val());
contact_email = escape($('#contact_email').val());
contact_comment = escape($('#contact_comment').val());
$.ajax({
  type: "POST",
  url: "/contact/",
  data: "ajax=1&contact_type=" + contact_type + "&contact_name=" + contact_name + "&contact_email=" + contact_email + "&contact_comment=" + contact_comment + "",
  beforeSend: function() {
	$(handler).block();
	//$('.error').remove();
  },
  success: function(data) {
	// Ajax Success
	if (data.indexOf("ajax-success") != -1) {	
	$('.boxyMe').html("<h1>Message Sent</h1><p>Your Message has been sent! We will be in touch as soon as we can.</p>")
	setTimeout(function(){Boxy.get('.boxyMe').hide();},3500);	
}
	else {
	  $(handler).unblock();
	  //check to see if error is present
	  if($('#contact_form .error').length > 0) {
   $('#contact_form .error').replaceWith(data);
}else{
	
    $('.boxy-wrapper .inline_footer').before(data);
    return;
}


	  
	}
  },
  error: function() {
	$(handler).unblock();
	alert("Please try again, a server error occurred");
  }
});
}
});

}




function finishUsernameCheck(id, response) {
  $('#username').removeClass('input_loading');
  $('#' + id).html(unescape(response));
  $('#' + id).fadeIn();
}

function friendAdd() {
  $('textarea.inputtextarea').growing();
  $('#friend_add').validate({
    rules: {
      comment: {
        maxlength: 1000
      }
    },
    messages: {
      comment: {
        maxlength: "Your message must not exceed 1000 characters"
      }
    },
    submitHandler: function (form) {
      jQuery(form).ajaxSubmit({
        beforeSend: function (request) {},
        success: function () {
          $('.boxy-wrapper').fadeOut("fast", function () {
			new Boxy("<div class='alert'><p><strong>Friend Request Sent.</strong></p><p>Your request has been sent for approval.</p></div>",{title: boxyTitle+" ?",autoClose:"3500"});
			$('#friendstatus').html("<p><span>This user has <strong>not yet</strong> <br/>accepted your friend request.</span></p>");
			$('#friendstatus p span').effect("highlight",{}, 5000);
		  });
        },
        error: function () {
          $.prompt('Please try again, a server error occurred');
        }
      });
    }
  });
}



/*
function photoButtons(){
	imageHeight = $('#photo_container').height();
	nextImg = $(".button_next").attr("href");
	prevImg = $(".button_prev").attr("href");
	$("#photo_container").prepend("<a href='"+prevImg+"' class='prev'><span>Prev</span></a><a href='"+nextImg+"' class='next'><span>Next</span></a>");
	$("#photo_container .prev, #photo_container .next").css("height", imageHeight);
	$("#photo_container").mouseenter(function(){
	$("#photo_container .prev, #photo_container .next").show();
	});
	$("#photo_container").mouseleave(function(){
	$("#photo_container .prev, #photo_container .next").hide();
	});	
}
*/

function photoSizetoggle(){
	
var smallPhotoHeight = $('#photo').height();

	
	// inject the button
	$('#photo_container').append("<span id='photo_size_toggle' class='ui_large_button hirez'>Hi-Res</span>")
	// do the toggle

$('#photo_size_toggle').toggle(function () {	
$(this).text('Normal').addClass('lowrez');
$('#content_container_wrapper').addClass('hirez');
$('#photo').addClass("supersize");



//alert(smallPhotoHeight)
	
$('#photo_container img').attr('width', '940');
//


var file = $('#photo').attr('src').replace('_large', '_basis');
$('#photo').attr('src', file);

	
// notes to go large - need to loop through 




var largePhotoHeight = $('#photo').height();
$('.note').each(function(index) {
$(this).width($(this).width()*(940/610));
$(this).height($(this).height()*(largePhotoHeight/smallPhotoHeight))
var test = $(this).css("left").replace('px', '');
var test1 = $(this).css("top").replace('px', '');
dom = test*(940/610)
dom1 = test1*(largePhotoHeight/smallPhotoHeight)
$(this).css("left", dom);
$(this).css("top", dom1);
$(this).next().css({left: dom + 'px'});
hmm = $(this).next().css("top")



//$(this).next().css({top: (parseInt(hmm)+parseInt($(this).height()*(largePhotoHeight/smallPhotoHeight))) + 'px'});
//$(this).next().css({top: note_p_top + 'px'});
//alert($(this).height())


});






//$('.note').width($('.note').width()*(940/610));
//$('.note').height($('.note').height()*(largePhotoHeight/smallPhotoHeight))
//var test = $('.note').css("left").replace('px', '');
//var test1 = $('.note').css("top").replace('px', '');
//dom = test*(940/610)
//dom1 = test1*(largePhotoHeight/smallPhotoHeight)
//$('.note').css("left", dom);
//$('.note').css("top", dom1);




/*
   $('#photo_container').mouseenter(function () {
      elem = $("#photo");
      if (elem.hasClass("supersize")) {
        //$('.note').hide();
      }
    });
*/	
	
  }, function () {
	  
var largePhotoHeight = $('#photo').height();
	  //alert(largePhotoHeight)
	  
	  	$(this).text('Hi-Res')
	 $('#content_container_wrapper').removeClass('hirez'); 
    $(this).removeClass('lowrez');
    $('#photo').removeClass("supersize");
	$('#photo_container img').attr('width', '610');
       



//alert(smallPhotoHeight)
	
	    var file = $('#photo').attr('src').replace('_basis', '_large');
        $('#photo').attr('src', file);
		
		
		
		// notes to go large - need to loop through 



$('.note').each(function(index) {
    //alert(index + ': ' + $(this).text());
	
$(this).width($(this).width()*(610/940));
$(this).height($(this).height()*(smallPhotoHeight/largePhotoHeight))


var test = $(this).css("left").replace('px', '');
var test1 = $(this).css("top").replace('px', '');

dom = test*(smallPhotoHeight/largePhotoHeight)
dom1 = test1*(smallPhotoHeight/largePhotoHeight)
$(this).css("left", dom);
$(this).css("top", dom1);


$(this).next().css({left: dom + 'px'});


	
	
  });


		
		
		
		
  });
	}




	







function rateMe(media){
$('.rate').rating({
  callback: function (value, link) {
    $('#rating').block();
	id = $('#photo, #videoSWF, #story').attr('name').replace(/[a-zA-Z_\s]/g, ''); 
    $.post('/apps/common/rateme.asp', {
      type: media,
      id: id,
      rating: value
    },
    function (data) {
	   $('#rating').unblock();
	  $('#rating h2').html("Rating <strong>submitted</strong> " + value + "/10");
	  $('.star_wrapper').hide();	  
    });
  },
  focus: function (value, link) {
    var tip = $('#rating h2 span');
    tip[0].data = tip[0].data || tip.html();
    tip.html(link.title || 'value: ' + value);
  },
  blur: function (value, link) {
    var tip = $('#rating h2 span');
    $('#rating h2 span').html(tip[0].data || '');
  }
});


$('#rating .star_wrapper .star').show();


}


function showaddnote(img, area) {
  imgOffset = $(img).offset();
  form_left = parseInt(imgOffset.left, 10) + parseInt(area.x1, 10);
  form_top = parseInt(imgOffset.top, 10) + parseInt(area.y1, 10) + parseInt(area.height, 10) + 5;
  $('#noteform').css({
    left: form_left + 'px',
    top: form_top + 'px'
  });
  $('#noteform').show();
  $('#noteform').css("z-index", 2);
  $('#tagx').val(area.x1);
  $('#tagy').val(area.y1);
  $('#tagheight').val(area.height);
  $('#tagwidth').val(area.width);
  $('#user_suggest, #tagUserId').val("");
}




    

// function injectTitle with green span on selected words

function injectTitle(str, div) {
  var TmpPos;
  var TitleP1;
  var TitleP2;
  var KeywordArray = ["Page", "Newsfeed", "Profile"];
  for (i = 0; i < KeywordArray.length; i++) {
    TmpPos = str.indexOf(KeywordArray[i]);
    if (TmpPos >= 0) {
      TitleP1 = str.substring(0, TmpPos);
      TitleP1 += ' <span>';
      TitleP2 = str.substring(TmpPos, 100);
      str = TitleP1 + TitleP2 + '</span>';
    }
  }
  $(div).html(str);
};

function mySummary() {



  window.location.hash="#summary"
  var str = $('#user_summary a').attr("title");
  var div = '#title';
  document.title = str +" on Jollywatcher - Where've you been?"
  injectTitle(str, div);
  $("body").removeClass().addClass("summary");
  $("#newsfeed,#about").hide();
  $("#summary").show();
//  return false;
};

function myNews() {
  window.location.hash ="#news"
  var str = $('#user_news a').attr("title");
  var div = '#title';
  document.title = str +" on Jollywatcher - Where've you been?"
  injectTitle(str, div);
  $("body").removeClass().addClass("news");
  $("#summary,#about").hide();
  $("#newsfeed").show();
  return false;
}
function myAbout() {
  window.location.hash ="#about"
  var str = $('#user_about a').attr("title");
  var div = '#title';
  document.title = str +" on Jollywatcher - Where've you been?"
  injectTitle(str, div);
  $("body").removeClass().addClass("about");
  $("#summary,#newsfeed").hide();
  $("#about").show();
  return false;
}

// 




$('#more_dashboard_news').live("click", function(){
var uid, pageno
uid = $(this).attr('class').replace("user",'');
pageno = $('#more_dashboard_news a').attr('rel');
$.ajax({ 
   	url: "/apps/admin/ajax_newsfeed.asp",
	data: "uid="+uid+"&pageno="+pageno+"",
	beforeSend:function(){
	$('#more_dashboard_news').block();
	},
	success: function(html){
	$('#more_dashboard_news').remove();
	$('#newsfeed').append(html);
   },
   error:function(){
	$('#more_dashboard_news').block();
   	alert("Please try again, a server error occurred");
   }
 });
return false;
});








function acknowledgeFriend(id,username,userdir,friendtype,ajax){
$.ajax({ 
   	url: "/apps/friend/acknowledge_friend_request.asp",
	data: "userid="+id+"&username="+username+"&userdir="+userdir+"&friendtype="+friendtype+"&ajax="+ajax+"",
	beforeSend:function(){
	$('#user'+id+'').block();
	},
	success: function(html){
   	$('#user'+id+'').html(html).unblock().effect("highlight", {}, 1500);
   },
   error:function(){
	$('#user'+id+'').unblock();
   	alert("Please try again, a server error occurred");
   }
 });
};



function showNote(i){
//alert(i);
$('#note'+i+', #notep'+i+'').css("display","block");

}

function hideNote(i){
$('#note'+i+', #notep'+i+'').css("display","none")
}


function noresults(){
new Boxy("<div class='boxyMe'><h3>Sorry your search found nothing.</h3><p>We currently have no content for that search criteria.</p></div>",{title:"No Results",autoClose:"3000"});
}
	




function itemDeleted(item){
new Boxy("<div class='boxyMe'><h3>"+item+"<strong> Deleted</strong></h3><p>This "+item+" has been removed</p></div>",{autoClose:"1500"});
}




function mediaAddModal(vid,media){
new Boxy($('#foobar'),{title:"Add your "+media+"",modal: true});$('#foobar').html("<iframe src='/apps/admin/"+media+"/iframe_"+media+"_add.asp?vid="+vid+"' height='400px' width='760px'>Photo upload</iframe>");
}



function domtest(){
Boxy.load("/video.asp",{filter: "#jw_videoSWF",title:"video",modal:true,afterShow:function(){createJollyVideo();},afterHide:function(){}});
}









function removeUser(id){
var tags = 'Are you sure you want to remove this user?<input type="hidden" id="userID" name="userID" value="'+ id +'" />';
$.prompt(tags,{ 
	buttons:{Delete:true, Cancel:false},
	callback: function(v,m){
		var uid = m.find('#userID').val();
			if(v){
				$('#user'+id+'').block();
					$.post('/apps/admin/friend/friend_delete.asp',{uid:id,ajax: "1"}, function(data){
					if(data = true){
						$("#wfcount").text(parseInt($("#wfcount").text())-1)
						$('#user'+id+'').fadeOut("slow",function(){});
							$('#user'+id+'').unblock();
							
						var wfcount = $('#wfcount').text();
								if (wfcount < 2) {
	  							$('#unpublishedJollysTitle h4').text("You have 1 Friend");
							};
							if (wfcount < 1) {
	  							$('#unpublishedJollysTitle, #unpublishedJollys').fadeOut("slow");
							};
							}else{
							$.prompt('An Error Occured while removing this user');
						}
					});
				}
			else{}
		}
	});
}


function removeComment(id) {
  var tags = 'Are you sure you want to remove this Comment?<input type="hidden" id="CommentID" name="CommentID" value="' + id + '" />';
  $.prompt(tags, {
    buttons: {
      Delete: true,
      Cancel: false
    },
    callback: function (v, m) {
      var cid = m.find('#CommentID').val();
      if (v) {
        $('#CommentID' + cid).block();
        $.post('/apps/comment/do/comment_delete.asp', {
          cid: cid,
          ajax: "1"
        },
        function (data) {
        if (data == 'comment deleted') {
			
$.pnotify({ pnotify_title: 'Comment Deleted',
pnotify_text: 'This comment has been deleted',
pnotify_notice_icon: 'picon picon-mail-unread-new',
pnotify_animate_speed: 'fast',
pnotify_history: false
}),


			


		$("#ajax_comments .comment_count").text(parseInt($("#ajax_comments .comment_count").text(), 10) - 1);
        $("#jolly_comments .comment_count").text(parseInt($("#jolly_comments .comment_count").text(), 10) - 1);
		
var commentCount = $("#ajax_comments .comment_count").text(); 

								if (commentCount < 1) {
	  							$('#unpublishedJollysTitle h4').text("You have 1 Friend");
								$('#ajax_comments').empty()
							};


$('#comment' + cid).fadeOut("slow", function () {
	$('#comment' + cid).remove();
	
		$('#ajax_comments ol li').removeClass();
	$('#ajax_comments ol li:odd').addClass('even');
	
	
	});



            //var cCount = $('#ajax_comments .comment_count').text();
           // var JcCount = $('#jolly_comments .comment_count').text();

          } else {
            $.prompt('An Error Occured');
          }
        });
      }
    }
  });
}		
			
			
			

			
			







function removeChat(id){
var tags = 'Are you sure you want to remove this Comment?<input type="hidden" id="UserChatID" name="UserChatID" value="'+ id +'" />';
$.prompt(tags,{ 
	buttons:{Delete:true, Cancel:false},
	callback: function(v,m){
		var cid = m.find('#UserChatID').val();
			if(v){
				$('#UserChatID'+cid).block(); 
				$.post('/apps/comment/do/chat_delete.asp',{cid:cid,ajax: "1"}, function(data){
					if(data = true){
						$(".comment_count").text(parseInt($(".comment_count").text())-1)
						$('#UserChatID'+cid).fadeOut("slow");
						$('#alert_chat_Added').fadeOut("slow");
						var cCount = $('.comment_count').text();
								if (cCount < 2) {
	  							$('#the_chat .panel_header h3').text("My 1 comment");
							};
							if (cCount < 1) {
	  							$('#the_chat, #comments_toggle').fadeOut("slow");
							};
							}else{
							$.prompt('An Error Occured while removing this user');
						}
					});
				}
			else{}
		}
	});
}





function removePhoto(id){
var tags = 'Are you sure you want to remove this Photo?<input type="hidden" id="photoID" name="photoID" value="'+ id +'" />';
$.prompt(tags,{ 
	buttons:{Delete:true, Cancel:false},
	callback: function(v,m){
		var vid = m.find('#photoID').val();
			if(v){
				$('.ui-tabs-panel').block(); 
				 //$.blockUI();
				$.post('/apps/video/delete_photo.asp',{photoid:pid,ajax: "1"}, function(data){
					if(data = true){
					$('.ui-tabs-panel').unblock(); 
						$('#photo_summary, #photo_comments').fadeOut("slow")
						$('#photo_container').fadeOut("slow",function(){
						$('#photo_container').append("<div class='alert'><p><strong>Photo Deleted: </strong>You have successfully deleted your photo</p></div>");
						});
								}else{
							$.prompt('An Error Occured while removing this user');
						}
					});
				}
			else{}
		}
	});
}

function removeVideo(id){
var tags = 'Are you sure you want to remove this Video?<input type="hidden" id="videoID" name="videoID" value="'+ id +'" />';
$.prompt(tags,{ 
	buttons:{Delete:true, Cancel:false},
	callback: function(v,m){
		var vid = m.find('#videoID').val();
			if(v){
				$('#left').block();
				$.post('/apps/admin/video/delete_video.asp',{videoid:vid,ajax: "1"}, function(data){
					if(data = true){
						$('#left').unblock();
						$('.edit_video, .del_video').slideUp(),
						$('#video_wrapper').fadeOut("slow",function(){
						$('#left').append("<div class='alert'><p><strong>Video Deleted: </strong>You have successfully deleted this video</p></div>");
						});
								}else{
							$.prompt('An Error Occured while removing this user');
						}
					});
				}
			else{}
		}
	});
}


function removeJolly1(id){
var tags = 'Are you sure you want to remove this Jolly?<input type="hidden" id="JollyID" name="JollyID" value="'+ id +'" />';
$.prompt(tags,{ 
	buttons:{Delete:true, Cancel:false},
	callback: function(v,m){
		var jid = m.find('#JollyID').val();
			if(v){
				$('#unpublishedJollys').block();
					$.post('/apps/admin/jolly/jolly_delete.asp',{vid:jid,ajax: "1"}, function(data){
					if(data = true){
						$("#ujcount").text(parseInt($("#ujcount").text())-1)
						$('#unpublishedJolly'+id).fadeOut("slow",function(){});
						$('#unpublishedJollys').unblock();
						new Boxy("<div class='boxyMe'><h3>Jolly<strong> Deleted</strong></h3><p>This Jolly has been removed</p></div>",{autoClose:"1500",afterShow:function() {location.href=('/jollys/')}})
						var ujCount = $('#ujcount').text();
								if (ujCount < 2) {
	  							$('#unpublishedJollysTitle h4').html("Your <span>1</span> Unpublished Jolly");
							};
							if (ujCount < 1) {
	  							$('#unpublishedJollysTitle, #unpublishedJollys').fadeOut("slow");
							};
							}else{
							$.prompt('An Error Occured while removing this user');
						}
					});
				}
			else{}
		}
	});
}



function removeJolly(id) {
  var txt = 'Are you sure you want to remove this Jolly?<input type="hidden" id="JollyID" name="JollyID" value="' + id + '" />';
  $.prompt(txt, {
    buttons: {
      Delete: true,
      Cancel: false
    },
    callback: function (v, m) {
      var jid = m.find('#JollyID').val();
      if (v) {
        $.post('/apps/admin/jolly/jolly_delete.asp', {
          vid: jid,
          ajax: "1"
        },
        function (data) {
          if (data == 'true') {
$("#ujcount").text(parseInt($("#ujcount").text(),10)-1);
var ujCount = $('#ujcount').text();
            if (ujCount < 2) {
              $('#unpublishedJollysTitle h4').html("Your <span>1</span> Unpublished Jolly");
            }
            if (ujCount < 1) {
              $('#unpublishedJollysTitle, #unpublishedJollys').fadeOut("slow");
            }
          } else {
            $.prompt('An Error Occured');
          }
        });
      }
    }
  });
}



function removeJolly1(id){var txt='Are you sure you want to remove this Jolly?<input type="hidden" id="JollyID" name="JollyID" value="'+id+'" />';$.prompt(txt,{buttons:{Delete:true,Cancel:false},callback:function(v,m){var jid=m.find('#JollyID').val();if(v){$.post('/apps/admin/jolly/jolly_delete.asp',{vid:jid,ajax:"1"},function(data){if(data=='true'){var ujCount = $('#ujcount').text();if(ujCount<2){$('#unpublishedJollysTitle h4').html("Your <span>1</span> Unpublished Jolly");}if(ujCount<1){$('#unpublishedJollysTitle, #unpublishedJollys').fadeOut("slow");}new Boxy("<div class='boxyMe'><h3>Jolly<strong> Deleted</strong></h3><p>This Jolly has been removed</p></div>",{autoClose:"1500",afterShow:function(){location.href=('/jollys/');}});}else{$.prompt('An Error Occured');}});}}});}

//Remove photo album stuff
function removePhotoAlbum(id){
var tags='Are you sure you want to delete all photos from this Jolly?<input type="hidden" id="jollyID" name="jollyID" value="'+id+'" />';
$.prompt(tags,{
buttons:{Delete:true,Cancel:false},
callback:function(v,m){
var pid=m.find('#jollyID').val();
if(v){
$('#left').block();
$.post('/apps/admin/photo/delete_photo_album.asp',{vid:pid,ajax:"1"},function(data){
if(data=true){
$('#left').unblock();
$('.edit_photos, .sort_photos, .del_photos').slideUp(),
$('#photos_container').fadeOut("slow",function(){
$('#left').append("<div class='alert'><p><strong>Photo Album Deleted: </strong>You have successfully deleted all these photos</p></div>");
});
}else{
$.prompt('An Error Occured while removing this user');
}
});
}
else{}
}
});
}


//Remove videos album stuff
function removeVideoAlbum(id){
var tags='Are you sure you want to delete all videos from this Jolly?<input type="hidden" id="jollyID" name="jollyID" value="'+id+'" />';
$.prompt(tags,{
buttons:{Delete:true,Cancel:false},
callback:function(v,m){
var pid=m.find('#jollyID').val();
if(v){
$('#left').block();
$.post('/apps/admin/video/delete_video_album.asp',{vid:pid,ajax:"1"},function(data){
if(data=true){
$('#left').unblock();
$('.edit_video, .sort_video, .del_video').slideUp(),
$('#videos_container').fadeOut("slow",function(){
$('#left').append("<div class='alert'><p><strong>Video Album Deleted: </strong>You have successfully deleted all these videos</p></div>");
});
}else{
$.prompt('An Error Occured while removing this user');
}
});
}
else{}
}
});
}









//




//function doproces(dom) {
//	$('#destination_'+dom).serializelist();
//	}







	
function map(vid,mapper){
if(mapper==undefined){mapper = 'G';}
flashvars = {kmlPath:"/apps/jolly/xml_jolly.asp?vid="+vid+"%26map="+mapper+""};
params = {wmode:"transparent", allowscriptaccess:"always", allowfullscreen:"true"};
attributes = {};
swfobject.embedSWF("/swf/map.swf", "map", "640", "420", "9.0.0","/swf/expressInstall.swf", flashvars, params, attributes);
}


function unsupportedBrowser(){
new Boxy("<div style='width:400px; padding:30px; float:left'><h1>Sorry Internet Explorer 6 is not supported. Click the yellow alert bar near the top of your screen to install a newer version.</h1><small>Still want to use Internet Explorer 6? No problem, use <a href='http://www.google.com/chromeframe'>Google Chrome Frame</a>.</small></div>",{modal: true});
}


function featurePhoto(){
//match the height of the photo to the outer container
var containerHeight = $('#content_container_clean_wrapper').height()+14;
$('#feature_photo_container').css({'height':containerHeight});	
if ($('#feature_photo').width() < 550){$('#feature_photo').width('610px').height('auto');}
// read more photo grow
$('#jolly .more').live("click", function (){								   
quoteOffset = $('#jolly .quote').height()-57;
$('#feature_photo_container').css({'height':containerHeight+quoteOffset});
$('#feature_photo').width('125%');						   
});
}


// JQ HoverImage Plugin
/// Date Drop Downs
function ge(){var a;for(var i=0;i<arguments.length;i++){var e=arguments[i];if(typeof e=='string')e=document.getElementById(e);if(arguments.length==1)return e;if(!a)a=new Array();a[a.length]=e}return a}function remove_node(a){if(a.removeNode)a.removeNode(true);else{for(var i=a.childNodes.length-1;i>=0;i--)remove_node(a.childNodes[i]);a.parentNode.removeChild(a)}return null}function drop_date_month_change(a,c,d){var a=ge(a);var c=ge(c);var d=d?ge(d):false;var e=month_get_num_days(a.value,d.value&&d.value!=-1?d.value:false);var b=c.options[0].value==-1?1:0;for(var i=c.options.length;i>e+b;i--){remove_node(c.options[i-1])}for(var i=c.options.length;i<e+b;i++){c.options[i]=new Option(i+(b?0:1))}}function drop_date_year_change(a,b,c){drop_date_month_change(a,b,c)}function month_get_num_days(a,b){var c;if(a==-1){return 31}c=new Date(b?b:1912,a,0);return c.getDate()}
// createCleanURLFromTitle
function createCleanURLFromTitle(sourceValue,destination){var sourceTitle=sourceValue.toLowerCase();var allowedCharacters="abcdefghijklmnopqrstuvwxyz0123456789";var output="";var currentChar;var lastCharacterWasSeparator;for(var sourceIndex=0;sourceIndex<sourceTitle.length;sourceIndex++){currentChar=sourceTitle.substr(sourceIndex,1);if(allowedCharacters.indexOf(currentChar)!=-1){output+=currentChar;lastCharacterWasSeparator=false}else{if((currentChar==" ")||(currentChar=="-")){if(!lastCharacterWasSeparator){output+="-";lastCharacterWasSeparator=true}}}}destination.value=output}
// signup signupCaptcha_getCookie
