/* Left Navigation
-------------------------------------------------------------- */

/* Allow the left navigation to expand/collapse */

$(document).ready(function(){ 
	$(".menu-header").click(function(){
		$(this).toggleClass("active");
		$(this).parents(".menu-block").find('.menu').slideToggle("slow");
		return false;
	});
});

/* Compare the current url to the url of each menu item, then add the class "currentpage" to the matching url */

$(document).ready(function(){
	var path = location.pathname.substring(1);
	if ( path )
	$('.navigation a[href$="' + path + '"]').addClass('currentpage');
	$('.navigation a[href$="' + path + '"]').parents("li").parents("ul").attr('style', 'display: block;');
});

/* Header
-------------------------------------------------------------- */

// Slider
$(document).ready(function(){
	$("#slider").easySlider({});
});

// Slider Expand Button
$(document).ready(function(){ 
	$("#slider #buttonEnglish a").click(function(){
		$("#slider").toggleClass("slider-expanded");
		$(this).text($(this).text() == 'Expand' ? 'Collapse' : 'Expand');
	});
});

// Slider Expand Button
$(document).ready(function(){ 
	$("#slider #buttonFrench a").click(function(){
	$("#slider").toggleClass("slider-expanded");
	$(this).text($(this).text() == 'Développer' ? 'Effondrement' : 'Développer');
	});
});

/* Quarterly Reports
-------------------------------------------------------------- */

function MM_swapImgRestore() {
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) {
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Sitemap
-------------------------------------------------------------- */

/* Strip the accordion functionality */

$(function() {
	$('#sitemap a').removeClass('expandable'); // Remove the expandable class
	$('#sitemap ul ul').removeClass('acitem'); // Remove the accordion item class
	$('#sitemap ul ul').attr('style', 'display: block;'); // Expand the accordion
});

/* Link Icons
-------------------------------------------------------------- */

$(document).ready(function() {
	if ($("body").hasClass("english")) {
		//Add external link icon to external links
		$('#right_column a').filter(function() {
			return this.hostname && this.hostname !== location.hostname;
		}).after(' <img class="external" src="/images/icons/icon_external.png" alt="External Link"/>');

		// Add pdf icons to pdf links
		$("#right_column a[href$='.pdf']").after(' <img class="external" src="/images/icons/file_types/icon_pdf.gif" alt="Adobe PDF Document"/>');
		
		// Add email icons to email links
		$("#right_column a[href^='mailto:']").after(' <img class="external" src="/images/icons/icon_mailto.png" alt="E-Mail"/>');
		
		// Add pdf icons to doc links
		$("#right_column a[href$='.doc']").after(' <img class="external" src="/images/icons/file_types/icon_doc.gif" alt="Microsoft Word Document"/>');
		
		// Add pdf icons to doc links
		$("#right_column a[href$='.xls']").after(' <img class="external" src="/images/icons/file_types/icon_xls.gif" alt="Microsoft Excel Document"/>');
	}
	if ($("body").hasClass("french")) {
		//Add external link icon to external links
		$('#right_column a').filter(function() {
			return this.hostname && this.hostname !== location.hostname;
		}).after(' <img class="external" src="/images/icons/icon_external.png" alt="Lien externe"/>');

		// Add pdf icons to pdf links
		$("#right_column a[href$='.pdf']").after(' <img class="external" src="/images/icons/file_types/icon_pdf.gif" alt="Document Adobe PDF"/>');
		
		// Add email icons to email links
		$("#right_column a[href^='mailto:']").after(' <img class="external" src="/images/icons/icon_mailto.png" alt="E-Mail"/>');
		
		// Add pdf icons to doc links
		$("#right_column a[href$='.doc']").after(' <img class="external" src="/images/icons/file_types/icon_doc.gif" alt="Document Microsoft Word"/>');
		
		// Add pdf icons to doc links
		$("#right_column a[href$='.xls']").after(' <img class="external" src="/images/icons/file_types/icon_xls.gif" alt="Document Microsoft Excel"/>');
	}
});

/* Application Lightbox
-------------------------------------------------------------- */

$(document).ready(function() {
	if($.browser.msie && $.browser.version < 7){
		$(".application").unbind();
	}
	$(".application").fancybox({
		'width'				: '95%',
		'height'			: '95%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'centerOnScroll'	: 'true'
	});
});

/* Standard Lightbox
-------------------------------------------------------------- */

$(document).ready(function() {	
	$(".lightbox a").fancybox({
		'centerOnScroll':	'true',
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic'
	});
});

/* Image Map
-------------------------------------------------------------- */

$(document).ready(function() {
	$(".lightbox map area").fancybox({
		'centerOnScroll':	'true',
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade'
	});
});

/* News
-------------------------------------------------------------- */

// Archived News Search

$(document).ready(function() {

    var options = { 
		target: '#newscontainer',
		success: showResponse
    };
	
    $('#formNewsArchive').submit(function() {
		$(".ajax-loader").show();
		$("#newscontainer").slideUp();
        $(this).ajaxSubmit(options);
        return false;
    });
	
	function showResponse() {
	$("#newscontainer").slideDown();
	$('.ajax-loader').hide();
	}
});

/* Search
-------------------------------------------------------------- */

// Autocomplete About

$(function() {
	var availableTags = [
		"News",
		"Northern Development",
		"Mines and Minerals",
		"Forestry",
		"Site Map",
		"Contact",
		"CLAIMaps",
		"Mining Claims Information",
		"Geology Ontario",
		"Mining Act",
		"OGS Earth",
		"Mining Lands",
		"Mines Group",
		"Ontario Geological Survey",
		"Northern Energy Credit"
	];
	
	$(".search-about-e").autocomplete({
		source: availableTags
	});
	$(".search-forestry-e").autocomplete({
		source: availableTags
	});
	$(".search-mines-e").autocomplete({
		source: availableTags
	});
	$(".search-northern_development-e").autocomplete({
		source: availableTags
	});
	$(".search-northern_energy_credit-e").autocomplete({
		source: availableTags
	});
});

$(function() {
	var availableTags = [
		"Nouvelles",
		"Développement du Nord",
		"Mines et des minéraux",
		"Forêts",
		"Plan du site",
		"Pour Nous Joindre",
		"CLAIMaps",
		"Claims miniers de l'information",
		"Géologie Ontario",
		"Loi sur les mines",
		"OGS Earth",
		"Des terrains miniers",
		"Groupe des mines",
		"Géologique de l'Ontario",
		"Crédit d'énergie du Nord"
	];
	
	$(".search-about-f").autocomplete({
		source: availableTags
	});
});

// Autocomplete NOHFC

$(function() {
	var availableTags = [
		"Projects List",
		"Frequently Asked Questions",
		"Marketing Event Partnership",
		"Northern Ontario Entrepreneur",
		"Enterprises North Job Creation",
		"Emerging Technology",
		"Infrastructure and Community Development",
		"Northern Ontario Young Entrepreneur",
		"Northern Ontario Youth Internship and Co-Op",
		"Northern Energy"
	];
	
	$(".search-nohfc-e").autocomplete({
		source: availableTags
	});
});

$(function() {
	var availableTags = [
		"Liste des projets approuvés par la SGFPNO",
		"Foire aux questions",
		"Partenariat pour la promotion d'activités",
		"Programme des entrepreneurs du nord de l'ontario",
		"Programme de création d’emplois par les entreprises du Nord",
		"Programme de technologies émergentes",
		"Programme d’amélioration de l’infrastructure et de développement communautaire",
		"Programme des jeunes entrepreneurs du Nord de l’Ontario",
		"Programme d’éducation coopérative et de stages pour les jeunes du Nord de l’Ontario",
		"Programme d’énergie pour le Nord"
	];
	
	$(".search-nohfc-f").autocomplete({
		source: availableTags
	});
});

/* Social Networks
-------------------------------------------------------------- */

$(document).ready(function(){ 
	$("#social .share").click(function(){
		$(".service").toggle();
	});
});

/* Advertisement Sliders
-------------------------------------------------------------- */

$(window).load(function() {
	$('#content-slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		slices:30,
		animSpeed:500, //Slide transition speed
		pauseTime:6000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});

/* UItoTop Function
-------------------------------------------------------------- */

$(document).ready(function() {
	$().UItoTop({ easingType: 'easeOutQuart' });
});

/* Datepicker
-------------------------------------------------------------- */

$(function() {
	// Default Settings
	$.datepicker.setDefaults({
		changeMonth: true,
		changeYear: true
	});
	
	// English
	$( ".datepicker-english" ).datepicker($.datepicker.regional[ "" ] );
	$( ".datepicker-english" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
	
	// French
	$( ".datepicker-french" ).datepicker($.datepicker.regional[ "fr" ] );
	$( ".datepicker-french" ).datepicker( "option", "dateFormat", 'yy-mm-dd' );
});

/* jQuery UI Tabs
-------------------------------------------------------------- */

$(function() {
	$( ".tabs" ).tabs({
		cookie: { expires: 30 }
	});
});

/* jQuery UI Accordion
-------------------------------------------------------------- */

$(function() {
		$( ".accordion" ).accordion({
			autoHeight: false,
			collapsible: true,
			navigation: true
		});
	});

/* Twitter
-------------------------------------------------------------- */

// MNDMF English

$(document).ready(function() {
	$('.ministry-tweets-english').tweetable({
		limit: 3,
		username: 'MNDMF',
		time: false,
		replies: false
	});
});

// MNDMF French

$(document).ready(function() {
	$('.ministry-tweets-french').tweetable({
		limit: 3,
		username: 'MDNMF',
		time: false,
		replies: false
	});
});

$(document).ready(function() {
	$('.nohfc-tweets-english').tweetable({
		limit: 3,
		username: 'NOHFC',
		time: false,
		replies: false
	});
});

// MNDMF French

$(document).ready(function() {
	$('.nohfc-tweets-french').tweetable({
		limit: 3,
		username: 'NOHFC',
		time: false,
		replies: false
	});
});
