var tipSpeed = 300;

$(function() {
	
	$("a[rel='external']").click(function () {
	$(this).attr({"target":"_blank"});
	});
	
	$(".moreFaq A").click(function() {
		$(".moreFaq").hide();
		$(".moreFaqCopy").slideDown("fast");
		return false;
	});
	
	$("#page_contactUs #content_broker, #tout_accident, #page_home #getQuoteLink, #page_home #accessQuoteLink").hover(function() {
		$(this).css({
			'cursor' : 'pointer'
		});
	});
	
	/*$("#page_contactUs #content_broker").click(function() {
		openContact('https://secure.canadainsuranceshop.ca/buyonline/app?brokersContact&lang=en'); 
		return false;
	});*/
	
	//$(".langToggle").click(function() {
	//	langToggle();
	//	return false;
	//});
	
	/*$("#tout_broker A").click(function() {
		openContact('https://secure.canadainsuranceshop.ca/buyonline/app?brokersContact&lang=en'); 
		return false;
	});*/
	
	$('#all_prevention_container .single_news_container:first').fadeIn(tipSpeed);
	$('#all_prevention_container .single_news_container:first').addClass('news_visible'); 
	
	$('#all_glossary_container .single_news_container:first').fadeIn(tipSpeed);
	$('#all_glossary_container .single_news_container:first').addClass('news_visible');    
	       
	var news_No1 = $('#all_prevention_container .single_news_container').length;
	var prev_html1 = 'Previous';
	var next_html1 = 'Next';
	
	var news_No2 = $('#all_glossary_container .single_news_container').length;
	var prev_html2 = 'Previous';
	var next_html2 = 'Next';
	
	$('#news_navigation_prevention').html('<ul><li id="preventionPrev"><a href="javascript:prev_news1();" title="Previous">' + prev_html1 + '</a></li>' + '<li id="preventionNext"><a href="javascript:next_news1();" title="Next">' + next_html1 + '</a></li>' + '<li id="preventionAll"><a href="/en/car-insurance-support/tips-on-prevention/" title="See All">See All</a></li></ul>'); 


	$('#news_navigation_glossary').html('<ul><li id="glossaryPrev"><a href="javascript:prev_news2();" title="Previous">' + prev_html2 + '</a></li>' + '<li id="glossaryNext"><a href="javascript:next_news2();" title="Next">' + next_html2 + '</a></li>' + '<li id="glossaryAll"><a href="/en/car-insurance-support/auto-insurance-glossary/" title="See All">See All</a></li></ul>'); 
});


function prev_news1(){
	if($('#all_prevention_container .news_visible').prev('#all_prevention_container .single_news_container').length){
		$('#all_prevention_container .news_visible').fadeOut(tipSpeed, function(){
	        $('#all_prevention_container .news_visible').removeClass('news_visible').prev('#all_prevention_container .single_news_container').addClass('news_visible').fadeIn(100); 
	    });
	    $('#preventionNext').css({
			'visibility' : 'visible'
		});
		
	} else {
		$('#preventionPrev').css({
			'visibility' : 'hidden'
		});
	}    
}

function next_news1(){
	if($('#all_prevention_container .news_visible').next('#all_prevention_container .single_news_container').length){
	    $('#all_prevention_container .news_visible').fadeOut(tipSpeed, function(){
	        $('#all_prevention_container .news_visible').removeClass('news_visible').next('#all_prevention_container .single_news_container').addClass('news_visible').fadeIn(100); 
	    });
	    $('#preventionPrev').css({
			'visibility' : 'visible'
		});
		
	} else {
		$('#preventionNext').css({
			'visibility' : 'hidden'
		});
	}
}

function prev_news2(){
	if($('#all_glossary_container .news_visible').prev('#all_glossary_container .single_news_container').length){
		$('#all_glossary_container .news_visible').fadeOut(tipSpeed, function(){
	        $('#all_glossary_container .news_visible').removeClass('news_visible').prev('#all_glossary_container .single_news_container').addClass('news_visible').fadeIn(100); 
	    });
	    $('#glossaryNext').css({
			'visibility' : 'visible'
		});
		
	} else {
		$('#glossaryPrev').css({
			'visibility' : 'hidden'
		});
		
	}
            
}

function next_news2(){
	if($('#all_glossary_container .news_visible').next('#all_glossary_container .single_news_container').length){
	    $('#all_glossary_container .news_visible').fadeOut(tipSpeed, function(){
	        $('#all_glossary_container .news_visible').removeClass('news_visible').next('#all_glossary_container .single_news_container').addClass('news_visible').fadeIn(100); 
	    });
	    $('#glossaryPrev').css({
			'visibility' : 'visible'
		});
		
	} else {
		$('#glossaryNext').css({
			'visibility' : 'hidden'
		});
		
	}
      
}

function langToggle() {
	var domain = window.location.host;
	var path = window.location.pathname;
	var toggle = "";
	
	if (path.indexOf("/fr/") == -1) {
	    toggle = path.replace("/en/", "/fr/");
	}
	
	var query = window.location.search;
	var complete = "http://" + domain + toggle + query;
	
	document.location.href = complete;	
}


function openContact(element) {
	var width  = 650;
	var height = 550;
	
	var posX = (screen.availWidth / 2) - (width / 2);
	var posY = (screen.availHeight / 2) - (height / 2);
	
	window.open(element, "Contact", "top=" + posY + ",left=" + posX + ",width=" + String(width) + ",height=" + String(height));
}


