$(document).ready(function() { 

	$('a.popupLink').bind('click', function(e) {
		popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''),'width=460, height=640, scrollbars'); e.preventDefault();
	});
	
	$('.dd_button iframe').css({"width":"420px","height":"30px"});

	/*$("#access a").mouseover(
		function () {
			if($(this).parent().hasClass('current-menu-item')) {
				
			} else {
				$(this).stop().animate({backgroundPosition:"0px -58px"}, {duration:500});
			}
	  	}
	);
	
	$("#access a").mouseout(
		function () {
			if($(this).parent().hasClass('current-menu-item')) {
				
			} else {
				$(this).stop().animate({backgroundPosition:"0px 0px"}, {duration:500});
			}
	  	}
	);*/

	
	$('.qaBlock:eq(0)').css({"padding-top":"0px"});
	$('.qaBlockQuestion').click(function(e) {
		if($(this).hasClass('open')) {
			$(this).next('.qaBlockAnswer').slideUp();	
			$(this).removeClass('open');
		} else {
			$('.qaBlockQuestion').removeClass('open');
			$(this).addClass('open');
			$('.qaBlockAnswer').slideUp();
			$(this).next('.qaBlockAnswer').stop(true, true);
			$(this).next('.qaBlockAnswer').slideDown();	
		}
		
		/*selectedElement = $(this).parent();
		answerHeight = $('.qaBlockAnswerContainer', selectedElement).height();
		if(!$(selectedElement).hasClass('qaBlockQuestionOpen')) {
			if($('.qaBlockQuestionOpen').length == 0) {
				$('.qaBlockAnswer', selectedElement).animate({height: 15+answerHeight+'px'},300, "swing");
				$(selectedElement).addClass('qaBlockQuestionOpen');
			} else {
				$('.qaBlockQuestionOpen .qaBlockAnswer').animate({height: '0px'},300, "swing");
				$('.qaBlock').removeClass('qaBlockQuestionOpen');
				$('.qaBlockAnswer', selectedElement).animate({height: 15+answerHeight+'px'},300, "swing");
				$(selectedElement).addClass('qaBlockQuestionOpen');
			}
		}*/
	}); 
	
});

function popupWindow(url, name, attributes){
	// Append popup to the URL if it does not already exist
	var queryStringExists = false;
	if(url.match(/\?/)) {
		queryStringExists = true;
	}
	if(queryStringExists) {
		// Only append if we haven't already got the parameter popup defined
		if(!url.match(/(\?|&)popup=/)) {
			url = url + '&popup=true';
		}
	} else {
		url = url + '?popup=true';
	}
	var baseTags = document.getElementsByTagName('base');
	if(baseTags != undefined && baseTags.length > 0) {
		url = baseTags[0].href + url;
	}
	var newWindow = window.open(url, name.replace(/[^A-z]/ig, ''), attributes);
	newWindow.focus();
} 

