/* CONFIG FOR JS */
var _path = '/';

function isset(varname)
{
	if(typeof( window[ varname ] ) != "undefined") return true;
	else return false;
}

function sure()
{
	var ask = confirm('Are you sure?');
	if (ask == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

$(function() {
	$(".theshouts").jCarouselLite({
		btnNext: ".next",
		btnPrev: ".prev",
		vertical: true,
		circular: false,
		visible: 3
	});

	$(".postfoot .rounded").hover(
							function(){
								if( $(this).attr("rel") == undefined)
								{
									
									$(this).attr("rel",$(this).css("width"));								
								}

								$(this).animate({ width: "105px" });
								$(this).find(".hide").show();
								
							},
							function(){
								$(this).find(".hide").hide();
								$(this).animate({ width:$(this).attr("rel") });								
							}
						);
});

function showstates()
{
	var country = $("#country").val();
	changecountry(country);

	if (country === 'US')
	{
		$("#state-p").fadeIn();
		$("#states").removeAttr("disabled");
	}
	else
	{
		if ($("#state-p").css("display") != 'none' )
		{
			$("#state-p").fadeOut();
			$("#states").attr("disabled","disabled");
		}
	}
}

function changecountry(country)
{
	country = country.toLowerCase();
	if ( country == '')
	{
		$("#countryimg").remove();
	}

	if ($("#countryimg").length > 0 )
	{
		$("#countryimg").attr("src","/images/flags/"+country+".gif");
	}
	else
	{
		$("#country").after("<img style=\"margin-left:5px;\" src=\"/images/flags/"+country+".gif\" id=\"countryimg\" alt=\"\"/>");
	}
}

function cp_imadd()
{
	var count = $(".ims").length;

	if ((count+1) > 5)
	{
		alert('You can only add up to 5 different type of IM Screen Names');
		return false;
	}

	var height = $("#im_opt").children("strong").css("height");
	var height2 = height.replace(/px/,'');

	var newheight = parseInt(height2) + 20 +"px";

	$("#im_opt").children("strong").css("height",newheight);

	var next = count+1;

	$(".ims:last").after("<span class=\"ims\">\n<input type=\"text\" name=\"im["+next+"]\" class=\"inputtext\" style=\"width:120px;\" />\n<select name=\"im_prog["+next+"]\" id=\"im_prog_"+next+"\"><option value=\"aim\">AIM</option><option value=\"skype\">Skype</option><option value=\"msn\">MSN</option><option value=\"ym\">Yahoo!</option><option value=\"gtalk\">gTalk</option></select>\n</span>");

	$(".ims:last").hide();
	$(".ims:last").slideDown('fast');

	return false;
}

function photo_addmore(msg)
{
	if (msg == undefined)
	{
		var msg = 'Publish';
	}

	var count = $(".addphotos").length;

	if ((count+1) > 10)
	{
		alert('You can only add up to 10 photos.');
		return false;
	}

	var next = count+1;

	$(".addphotos:last").after("<li class=\"addphotos\"><input class=\"photo\" type=\"file\" name=\"photo["+next+"]\" id=\"photo"+next+"\" onchange=\"check(this,"+next+",'"+msg+"')\"/><span class=\"uploadnotes\" id=\"note-"+next+"\"></span></li>");

	$(".addphotos:last").hide();
	$(".addphotos:last").slideDown('fast');

	return false;
}

/*
* resizehandle.js (c) Fil 2007, plugin pour jQuery ecrit
* a partir du fichier resize.js du projet DotClear
* (c) 2005 Nicolas Martin & Olivier Meunier and contributors
*/
jQuery.fn.resizehandle = function() {
return this.each(function() {
var me = jQuery(this);
me.after(
  jQuery('<div class="resizehandle" title="Click and hold to resize textbox"></div>')
  .bind('mousedown', function(e) {
	var h = me.height();
	var y = e.clientY;
	var moveHandler = function(e) {
	  me
	  .height(Math.max(20, e.clientY + h - y));
	};
	var upHandler = function(e) {
	  jQuery('html')
	  .unbind('mousemove',moveHandler)
	  .unbind('mouseup',upHandler);
	};
	jQuery('html')
	.bind('mousemove', moveHandler)
	.bind('mouseup', upHandler);
  })
);
});
}

function useropt()
{
	$("#useropt").toggle();
}

function changeme()
{
	var ask = confirm('Are you sure you want to message another person instead?');
	if ( ask == false )
	{
		return false;
	}
	
	$("#changeme").remove();
	$("#to_id").show();

	return false;							
}

function addfriend(friend_id,name)
{	
	var html = '';	
	var html = $.ajax({
					   type: "GET",
					   url: '/ajax.friend.php?act=addfriend',
					   data: 'friend_id='+friend_id,
					   async: false,
					   global: true
					 }).responseText;

	var test = html.search(/friend/);
	if ( test == -1 )
	{
		alert(html);
		return false;
	}
	
	$(".friend").html(html).fadeIn('slow');	

	alert('You have added "'+name+'" as a friend');

	return false;
}

function removefriend(friend_id,name)
{
	var html = '';	
	var html = $.ajax({
					   type: "GET",
					   url: '/ajax.friend.php?act=removefriend',
					   data: 'friend_id='+friend_id,
					   async: false,
					   global: true
					 }).responseText;

	var test = html.search(/friend/);
	if ( test == -1 )
	{
		alert(html);
		return false;
	}
	
	$(".friend").html(html).fadeIn('slow');

	alert('You have removed "'+name+'" from your friends list');
	

	return false;
}

function addcomment() 
{
	//userid
	if ( $("#userid").val() != undefined )
	{
		var userid = $("#userid").val();
	}
	else
	{
		var userid = 0;
	}

	//fbid
	if ($("#fbid").val() != undefined )
	{
		var fbid = $("#fbid").val();
	}
	else	
	{
		var fbid = 0;
	}

	if (userid == 0 && fbid == 0)
	{
		var user_name = $("#comment_name").val();
		if (  user_name == '' || user_name.length < 2 )
		{
			alert('Please enter a name (min. 2 chars)');
			return false;
		}

		var user_email = $("#comment_email").val();
		if ( user_email == '' || user_email.length < 5 )
		{
			alert('Please enter your email');
			return false;
		}
	}

	if ( $("#comment_post").val() == '' )
	{
		alert('You must write something first.');
		return false;
	}

	if ( $("#comment_post").val().length < 3 )
	{
		alert('Your comments is too short! It must be more than 3 characters');
		return false;
	}
	
	if ($("#newcomments").html().length > 1)
	{
		$("#newcomments").children(".Note").remove();
	}

	//serialize data
	 var data = $("#addcomment_form  input, #addcomment_form textarea").serialize();
	 data = data + '&fbname='+$("#fbname").html();

	 var html = '';
	 var html = $.ajax({
					   type: "POST",
					   url: "/comment.php?ajax=1",
					   data: data,
					   async: false
					 }).responseText;
	
	var test = html.search(/<div/);
	if ( test == -1 )
	{
		alert(html);
		return false;
	}

	$("#newcomments").append(html);
	$(".comments:last").hide();
	$(".comments:last").fadeIn('slow');
	
	var totalcomments = $("#totalcomments").html();
	var newtotalcomments = parseInt(totalcomments)+1;

	$("#totalcomments").html(newtotalcomments);	
	
	$("#comment_post").val("");

	setTimeout("$('.notes').fadeOut('slow');",2500);	


	return false;
}

var cururl = document.location.toString();
if (cururl.match('#'))
{
	var myanchor = cururl.split('#')[1];
	if (myanchor.match('photo/'))
	{
	  this.location = myanchor;
	}
}

function changephoto(thumb,id,thumbname,pparent,link,desc)
{
	document.title = 'Photo '+thumbname+' in '+pparent+' - Munzir 08';
	$("#photoname").html(thumbname);

	$("#loadimg").show();
	$(".carousel ul li").each(function()
	{
		if ( $(this).hasClass("active") )
		{
			$(this).removeClass("active");
		}
	});
	
	$("#commentswrap").html("<img src='/images/loader.gif' alt='loading' />");
	var html = '';	
	var html = $.ajax({
					   type: "GET",
					   url: '/ajax.comments.php',
					   data: 'id='+id,
					   async: false,
					   global: true
					 }).responseText;

	$("#commentswrap").html(html);

	$("#photothumb").empty();
	$("#photothumb").image(thumb,function()
	{
		$("#loadimg").hide();
	});

	$(".photodesc").html(desc);

	$("#photo-"+id).addClass("active");
	/*$("#photothumb img").wrap("<a href=\""+link+"\"></a>");*/
	$("#fullsizelink").attr("href",link);
	$("#fullsizelink").nyroModal();
	 
	return false;
}

$.fn.image = function(src, f){
   return this.each(function(){
     $("<img />").appendTo(this).each(function(){
     	this.src = src;
     	this.onload = f;
     });
   });
}
