/*Jquery Standard Library

Version: 1.0
Date Created: 21/04/08
Author: Ritchie Anesco
Comments: Jquery Framework requred

---------------------------------------------------------------------------*/



//Bookmark core function
function bookmark(url, description) { 
	var netscape="Netscape User's hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer') {
		window.external.AddFavorite(url, description);
	} else if (navigator.appName=='Netscape') {
		alert(netscape);
	}
}



//SUBSCRIPTION SCRIPT
jQuery.fn.blindToggle = function(speed, easing, callback) {
	var h = 0;
	var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom')) -40;
	return this.animate({marginTop: parseInt(this.css('marginTop')) > 0 ? -h : +h }, speed, easing, callback);
};



//Add outer div for inner div to slide up and hide	
function subscription() {
	
	$("#subscribe").addClass("reposition");
	var $box = $('#subscribe').wrap('<div id="box-outer"></div>');
	//$box.blindToggle();
	
	
//	$('p#subscribe-toggle a').click(function() {
//		$box.blindToggle(400);
//		$(this).toggleClass("active");
//		var validator = $("#subscription-form").validate();
//		validator.resetForm();	
//		$("#subscription-response").hide(400);
//		return false;
//	 });
	
}



function showSection(id, hideitems) {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf(hideitems) == -1) continue;
		if (divs[i].getAttribute("id") != id) {
			$(divs[i]).hide();
		} else {
			$(divs[i]).fadeIn('slow');
		}
	}
}


//find id on click and send to showSection function
function subnav(list, button, hideitems) {	
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById(list)) return false;
	var nav = document.getElementById(list);
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		var sectionId = links[i].getAttribute("href").split("#")[1];
		if (!document.getElementById(sectionId)) continue;
		document.getElementById(sectionId).style.display = "none";
		links[i].destination = sectionId;
		links[i].onclick = function() {
			$(button).removeClass('on');
			$(this).addClass('on');
			showSection(this.destination,hideitems);
			return false;
		}
	}
}


//Change widths on affiliate containers
function columnHeight() {

	var maincontent_height = $('#main-content').height(); 
	var subcontent_height = $('#sub-content').height(); 

	if(maincontent_height < subcontent_height) { 
		$('.box-container .middle').height((subcontent_height-25) + "px"); 
	} 
	else if(maincontent_height > subcontent_height) { 
		$('#swf-holder').height((maincontent_height-200) + "px"); 		
		$('.home #swf-holder').height((maincontent_height-30) + "px"); 
	}
	
	
}


$(document).ready( function() {
							
	//$('<div id="preloader"><img src="../../Content/images/shared/misc/loading.gif" alt="loading..."></div>').insertBefore('#wrap');
    //timer = setTimeout(function() { $('#preloader').fadeOut(400);	  }, 2000);
							
							    
	//popup window
	$("a.popup").click( function() {
        window.open( $(this).attr('href'), "popup", "width=860, height=670" );
        return false;
    });


	//external link
	$("a.newwindow").click( function() {
        this.target = "_blank";
    });
	
	
	//print
	$("p.print").click( function() {
		if (window.print) window.print();
		else if (VBS) printIt();
		else alert('This script does not work in your browser');
		return false;

	});
	
	
	//back
	$("p.back").click( function() {
		window.back()
		return false;
    });
	
	
	//bookmark
	$("a.bookmark").click( function() {
		bookmark(this.getAttribute("href"), this.getAttribute("title"));
		return false;
    });
	
	//Text Increase/Decrease	
	//textresize();
	
	
	//Alternative Striped Tables  
	$('table.alternative tbody tr:not([th]):odd').addClass('odd');
 	$('table.alternative tbody tr:not([th]):even').addClass('even');	
	
	
	subscription();
	
	subnav("services-list",".service-button","service-detail");
	
	$('#planner').show();
	$('#overview').show();
	$('#property-school').show();

	$('#services-list li a:eq(0)').addClass('on');
	
	$('#info').show();
	
	//columnHeight();

	
});




