// JavaScript Document
function fIsCheckBoxGroupChecked(sCBGName){
	var oCBG = document.getElementsByName(sCBGName);
	for(var nCount=0; nCount < oCBG.length; nCount++){
		if (oCBG[nCount].checked){
			return true;
		}
	}
	return false;
}

$(document).ready(function(){
	$("#subnav.gallery a").click(function(){
		$(".panel").hide();
		$("#panel"+this.title).show();
		$("#subnav.gallery a").removeClass("active");
		$(this).addClass("active");		
		return false;
	});
	if ($("#mainimage").length > 0){
		$("#mainimage").cycle({ 
			fx: 'fade',
			before: function(){
				$("#mainimage img.elementhide").removeClass("elementhide");
			}
		});
	}
	if ($("#accordion").length > 0){
		$("#accordion").accordion({
			active: false,
			autoheight: false,
			header: ".heading"
		});
	}
	$('.jqHoverMap').mouseover(function(){
		var arrItems = this.title.split(' | ');
		var sHTML = "";
		if (arrItems[0] != ''){
			sHTML = sHTML + "<p>" + arrItems[0] + "</p>";
		}
		if (arrItems[1] != ''){
			sHTML = sHTML + "<p class=\"textformbigyellow\"><em>" + arrItems[1] + "</em></p>";
		}
		if (arrItems[2] != ''){
			sHTML = sHTML + "<p>" + arrItems[2] + "</p>";
		}
		$('#SiteDetails').html(sHTML);
	});
	$('.jqHoverMap').mouseout(function(){
		$('#SiteDetails').html('');
	});
	
	$('#frmRegister').submit(function(){
		var bValid = true;
		$('.jqRequired').each(function(nIndex){
			if ($(this).val() == ''){
				bValid = false;
			}
		});
		if (document.getElementsByName('cbgStatus').length != 0){
			if (! fIsCheckBoxGroupChecked('cbgStatus')){
				bValid = false;
			}
		}
		if (document.getElementsByName('cbgPlanType').length != 0){
			if (! fIsCheckBoxGroupChecked('cbgPlanType')){
				bValid = false;
			}
		}
		if (document.getElementsByName('cbgPriceRange').length != 0){
			if (! fIsCheckBoxGroupChecked('cbgPriceRange')){
				bValid = false;
			}
		}
		if (document.getElementsByName('cbgCurrentResidence').length != 0){
			if (! fIsCheckBoxGroupChecked('cbgCurrentResidence')){
				bValid = false;
			}
		}
		if (document.getElementsByName('cbgMoving').length != 0){
			if (! fIsCheckBoxGroupChecked('cbgMoving')){
				bValid = false;
			}
		}
		if (document.getElementsByName('cbgHeardFrom').length != 0){
			if (! fIsCheckBoxGroupChecked('cbgHeardFrom')){
				bValid = false;
			}
		}
		if (! bValid){
			alert("Please fill in all fields.");	
		}
		
		return bValid;
	});
	if ($("#videoIntro").length > 0){
		var oContainer = $("#container");
		var oOffset = oContainer.offset();
		var nLeft = parseInt(oOffset.left + 814) + "px";
		$("#videoIntro").css("left",nLeft);
	}
	if ($("#videoIntro2").length > 0){
		var oContainer = $("#container");
		var oOffset = oContainer.offset();
		var nLeft = parseInt(oOffset.left + 814) + "px";
		$("#videoIntro2").css("left",nLeft);
	}
});
