var currentLocation = window.location.toString();  // find out what page we are on
var hostName = 'http://'+ window.location.hostname; // find our current domain name
var uriString = currentLocation.replace(hostName, '');  // get our segments minus our domain name
var uriSegment = uriString.split('/'); //create our segment array

//alert(uriSegment[5]);
var activeAcc = "";

if(typeof uriSegment[4]  == "undefined")
{
	activeAcc = parseInt(0);
}
else
{
	activeAcc = parseInt(uriSegment[4]);
}

$(document).ready(function() {
	
	// ** NEWSLETTER SUBSCRIPTION ** //
	$('#newsletter').submit(function(e){
		$('#nws-feedback').animate({'opacity':0}, 0);
		e.preventDefault();
		if($('#nws_email').hasClass('focused')){
			//do post
			$.ajax({
				type: 'POST',
				url: $('#newsletter').attr('action'),
				data: $('#newsletter').serialize(),
				success: function(data){
					$('#nws-feedback').html(data);
					$('#nws-feedback').animate({'opacity':1}, 500);
				}
			});
		} else {
			$('#nws-feedback').animate({'opacity':1}, 500);
		}
	});
	// ** //
	
	// ** PORTAL SLIDER ** //
	$('#portalslider').anythingSlider({
		autoPlay		: true,
		pauseOnHover	: true,
		width			: 650,
		height			: 250,
		forwardText 	: "&raquo;",
		backText 		: "&laquo;",
		startText 		: "&#x25BA;",   // Start button text
		stopText 		: "||",
		delay			: 5000,
		animationTime	: 600,
		onSlideComplete : function(slider){
			// alert('Welcome to Slide #' + slider.currentPage);
		}
	});
	// ** //
	
	// ** CONTENT ACCORDION ** //
	$('.content-acc').accordion({ autoHeight: false, clearStyle: true, active: activeAcc
	 });
	// ** //
	
	// ** COMMON FUNCTIONS ** //
	// -- FORM FIELDS LABELING -- //
	$('input[title], textarea[title]').each(function() {
		if($(this).val() === '') {
			$(this).val($(this).attr('title'));
		}
		
		$(this).focus(function() {
			if($(this).val() === $(this).attr('title')) {
				$(this).val('').addClass('focused'); 
			}
		});
		
		$(this).blur(function() {
			if($(this).val() === '') {
				$(this).val($(this).attr('title')).removeClass('focused'); 
			}
		});
	});
	// ** //
	/*
	if ($.browser.msie) {
			$('.profit').css('marginTop', -10);
	}
	*/
	// ** //
	
	$('a.external').click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
	});
	

	$('html').click(function() {
		//Hide the menus if visible
		$('.boverlay').fadeOut(500);
		$('.overlay').fadeOut(800);
	});

	$('.boverlay').click(function(event){
		event.stopPropagation();
	});
 
	
	
	if(!$.browser.msie){
		$('.overlay').fadeIn(500, function(e){
			$('.boverlay').fadeIn(500, function(e){
				$('.boverlay').click(function(e){
					$('.boverlay').fadeOut(500);
					$('.overlay').fadeOut(800);
				});
			});
		});
	} else {
		$('.overlay').css({'display':'block', 'opacity':.7});
		$('.boverlay').fadeIn(500, function(e){
			$('.boverlay').click(function(e){
				$('.boverlay').fadeOut(500);
				$('.overlay').fadeOut(800);
			});
		});
	}
	if(!$.browser.msie){
		$('.overlay').fadeIn(500, function(e){
			$('.boverlay2').fadeIn(500, function(e){
				$('.boverlay2').click(function(e){
					$('.boverlay2').fadeOut(500);
					$('.overlay').fadeOut(800);
				});
			});
		});
	} else {
		$('.overlay').css({'display':'block', 'opacity':0.7});
		$('.boverlay2').fadeIn(500, function(e){
			$('.boverlay2').click(function(e){
				$('.boverlay2').fadeOut(500);
				$('.overlay').fadeOut(800);
			});
		});
	}

	$('a#btnClose').click(function(e){
		e.preventDefault();
		$('.boverlay').fadeOut(500);
		$('.overlay').fadeOut(500);
		$(this).fadeOut(500);
	});
	
	$(document).keyup(function(e) {
		if (e.keyCode == 27) {
		//	alert('pressed escape');
			$('.boverlay').fadeOut(500);
			$('.overlay').fadeOut(500);
		}
	});
	
});

