$(function() {
   $('#homePics').cycle();
	 
	 $(".popCalendar").datepicker({dateFormat: 'mm/dd/yy', showOn: 'button', buttonImage: 'images/icons/calendar.png', changeMonth: true,changeYear: true,buttonImageOnly: true});
});

$(document).ready(function() {
	mainmenu();
	
	$("a#blImage").fancybox();
	
	$('.sortList').sortable({
		opacity: '0.75',
		placeholder: 'placeholder',
		update: function(e, ui){serial = $(this).sortable("serialize");
		$.ajax({
			url: "index.php",
			type: "POST",
			data: serial,
			success: function(html){
				/*
				$('#message').fadeIn('slow');
				$('#message').html(html);
				$('#message').animate({opacity: 1.0}, 1000);
				$('#message').fadeOut('slow');
				*/
			}
			});
		}
	});
});

function mainmenu(){
	$(" #topNav ul ").css({display: "none"}); // Opera Fix
	$(" #topNav li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});
}

function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  
	// search email text for regular exp matches
  if (strEmail.search(validRegExp) == -1) {
  	return false;
  } 
  return true; 
}

function loginAccount(){
	var str = $("#frmLogin").serialize();
	$.ajax({
		type: "GET",
		url: "/index.php",
		data: "sb_action=login_account&"+str,
		success: function(html){
			if(html == 'success'){
				window.location = '/sb-main.php';
			}else{
				$("#loginMessage").html(html);
				$("#loginMessage").slideDown("slow");
			}
		}
	});
}

function addFriend(member_id,friend_id){
	$.ajax({
		type: "GET",
		url: "/index.php",
		data: "sb_action=add_friend&member_id="+member_id+"&friend_id="+friend_id,
		success: function(html){
			$('#leftAddFriend').html(html);
			//$('#leftAddFriend').hide();
			//$("#divMessage").html(html);
			//popDiv('divMessage',600, 300);
		}
	});
}

function displayFriendError(){
	$.ajax({
		type: "GET",
		url: "/index.php",
		data: "sb_action=display_friend_error",
		success: function(html){
			$("#divMessage").html(html);
			popDiv('divMessage',600, 300);
		}
	});
}

// toggle div tag
function toggleDiv(divTag, display){
	if(display == 1){
		$("#"+divTag).slideDown("slow");
	}else{
		$("#"+divTag).slideUp("slow");
	}
}

// toggle div tag
function toggleElement(divTag, divClass){
	$("."+divClass).slideUp("slow");
	$("#"+divTag).slideDown("slow");
}

function unpopDiv(divTag){
	$("#"+divTag).fadeOut("slow");
}

function popDiv(divTag, dwidth, dheight){
	var A = document.getElementById(divTag);
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		var C = window.innerWidth;
		var D = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		var C = document.documentElement.clientWidth;
		var D = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		var C = document.body.clientWidth;
		var D = document.body.clientHeight;
	}

	//must display block first to have clientWidth and clientHeight
	//A.style.display = "block";

	//var elementWidth = A.clientWidth;
	//var elementHeight = A.clientHeight;
	
	var elementWidth = dwidth;
	var elementHeight = dheight;
	
	A.style.top = String(Math.round((D-elementHeight)/2))+"px";
	A.style.left = String(Math.round((C-elementWidth)/2))+"px";
	
	$("#"+divTag).fadeIn("slow");
}

function retrieveStream(divTag,member_id,limit,startdate,enddate){
	$.ajax({
		type: "GET",
		url: "/index.php",
		data: "sb_action=get_live_stream&member_id="+member_id+"&limit="+limit+"&startdate="+startdate+"&enddate="+enddate,
		success: function(html){
			//if(divTag == 'divLiveStream2'){
				//$('#divStreamLoading2').hide();
			//}
			$('#'+divTag).html(html);
			$('#divStreamLoading').hide();
		}
	});
}



