$(document).ready(function() {
    
/*    var agent = navigator.userAgent.toLowerCase();
	var is_iphone = ((agent.indexOf('iphone') != -1));
	var is_ipad = ((agent.indexOf('ipad') != -1));
	
	if (is_iphone) { 
		
	}	
	
	if (is_ipad) { 

	}*/
	
	var ie_version = getInternetExplorerVersion();
	
	// Setup a default popup link binding
    //$('a.popupLink').bind('click', function(e) { popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''),'width=600, height=800, scrollbars'); e.preventDefault(); });

    if($('.qaBlock').length > 0) {
    	$('.qaBlock:eq(0)').css({"padding-top":"0px"});
    	$('.qaBlockQuestion').click(function(e) {
        	$('.qaBlockQuestion').children('h3').removeClass('open');
        	$(this).children('h3').addClass('open');
            $('.qaBlockAnswer').stop(true, true);
            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');
                }
            } else {
                $('.qaBlockQuestionOpen .qaBlockAnswer').animate({height: '0px'},300, "swing");
                $('.qaBlock').removeClass('qaBlockQuestionOpen');
            }
        });
    }
});

function getInternetExplorerVersion() {
	var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

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();
}

