
var profileLinks = new Array();
var expertiseLinks = new Array();
var videoLinks = new Array();
var customSelectLinks = new Array();
var customHomeSelectLinks = new Array();
var customHeaderSelectLinks = new Array();
var customFormatSelectLinks = new Array();
var buttons = new Array();

var lang = (window.location.href.indexOf("/en/")!=-1)?"en":"fr";



function Init () {
	if($('content')) {
		$('content').getElements('.lawyer-profile li a').each(function (el) {
			profileLinks[el.id] = new ProfileLink(el);
		});
		$('content').getElements('.expertise-detail li a').each(function (el) {
			expertiseLinks[el.id] = new ExpertiseLink(el);
		});
	}
	
	$$('.button').each(function (el) {
		buttons[el.id] = new Button(el);
	});
	
	if($$('.video-link')) {
		$$('.video-link').each(function (el) {
			videoLinks[el.id] = new VideoLink(el);
		});
	}
	
	
	if($('custom_select_header')) {
		$('custom_select_header').getElements('.custom_options_header li a').each(function (el) {
			customHeaderSelectLinks[el.id] = new CustomHeaderSelectLink(el);
		});
		
		$('custom_select_header').getElement('img').addEvent('click', function (e) {
				if($$('.custom_options_header').getStyle('display') == 'none') {
					$$('.custom_options_header').setStyle('display','block');
				} else {
					$$('.custom_options_header').setStyle('display','none');
				}
		  });
	}
	
	if($('custom_select')) {
		$('custom_select').getElements('#custom_options li a').each(function (el) {
			customSelectLinks[el.id] = new CustomSelectLink(el);
		});
		
		$('custom_select').getElement('img').addEvent('click', function (e) {
				if($('custom_options').getStyle('display') == 'none') {
					$('custom_options').setStyle('display','block');
					$('custom_select_format').setStyle('visibility','hidden');
				} else {
					$('custom_options').setStyle('display','none');
					$('custom_select_format').setStyle('visibility','visible');
				}
		  });
	}
	
	if($('custom_select_home')) {
		$('custom_select_home').getElements('.custom_options li a').each(function (el) {
			customHomeSelectLinks[el.id] = new CustomHomeSelectLink(el);
		});
		
		$('custom_select_home').getElement('img').addEvent('click', function (e) {
				if($$('.custom_options').getStyle('display') == 'none') {
					$$('.custom_options').setStyle('display','block');
				} else {
					$$('.custom_options').setStyle('display','none');
				}
		  });
	}
	
	if($('custom_select_format')) {
		$('custom_select_format').getElements('#custom_options_format li a').each(function (el) {
			customFormatSelectLinks[el.id] = new CustomFormatSelectLink(el);
		});
		
		$('custom_select_format').getElement('img').addEvent('click', function (e) {
				if($('custom_options_format').getStyle('display') == 'none') {
					$('custom_options_format').setStyle('display','block');
				} else {
					$('custom_options_format').setStyle('display','none');
				}
		  });
	}	
	
	if(getCookie('fontToggle') == "large") {
		$('content').getElements('p').each( function (el) {
			el.toggleClass('increaseTextSize');
		});
		$('content').getElements('li').each( function (el) {
			el.toggleClass('increaseTextSize');
		});
		$('content').getElements('td').each( function (el) {
			el.toggleClass('increaseTextSize');
		});
		$('content').getElements('h5').each( function (el) {
			el.toggleClass('increaseTextSize');
		});
		$('content').getElements('h6').each( function (el) {
			el.toggleClass('increaseTextSize');
		});
	}

}

var ProfileLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			e.preventDefault();
			openDiv = el.href.substr(el.href.lastIndexOf('/')+1);
			//openDiv = el.name;
			this.toggleOff(el);
			this.toggleOn(el);
		}.bind(ref));
	},
	toggleOff: function(el) {
		$('content').getElements('.profile-details').each(function (el) {
			el.setStyle('display', 'none');
		});
		
		$('content').getElements('.lawyer-profile li a').each(function (el) {
			el.removeClass('active');
		});
	},
	toggleOn: function(el) {
		$(openDiv).setStyle('display','block');
		el.addClass('active');
	}
});

var ExpertiseLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			openDiv = el.name;
			this.toggleOff(el);
			this.toggleOn(el);
		}.bind(ref));
	},
	toggleOff: function(el) {
		$('content').getElements('.profile-details').each(function (el) {
			el.setStyle('display', 'none');
		});
		
		$('content').getElements('.expertise-detail li a').each(function (el) {
			el.removeClass('active');
		});
	},
	toggleOn: function(el) {
		$(openDiv).setStyle('display','block');
		el.addClass('active');
	}
	
});

var Button = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		this.src = el.getProperty('src');
		el.addEvent('mouseover', function (e) {
			e = new Event(e);
			//uncomment once all over .gifs are made
			el.setProperty('src',this.src.replace(/.gif/,'-over.gif'));
		}.bind(ref));
		el.addEvent('mouseout', function (e) {
			e = new Event(e);
			el.setProperty('src',this.src);
		}.bind(ref));
	}
});

var CustomSelectLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			e.preventDefault();
			expID = el.href.substr(el.href.lastIndexOf('/')+1);
			expVal = el.getText();
			$('custom_select_text').setProperty('value',expVal);
			$('custom_select_ID').setProperty('value',expID);
			$$('.custom_options').setStyle('display','none');
			$('custom_select_format').setStyle('visibility','visible');
		}.bind(ref));
	}
});
var CustomHomeSelectLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			e.preventDefault();
			expID = el.href.substr(el.href.lastIndexOf('/')+1);
			expVal = el.getText();
			$('custom_select_text_home').setProperty('value',expVal);
			$('custom_select_ID_home').setProperty('value',expID);
			$$('.custom_options').setStyle('display','none');
		}.bind(ref));
	}
});
var CustomFormatSelectLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			e.preventDefault();
			expID = el.href.substr(el.href.lastIndexOf('/')+1);
			expVal = el.getText();
			$('custom_select_format_text').setProperty('value',expVal);
			$('custom_select_format_ID').setProperty('value',expID);
			$('custom_options_format').setStyle('display','none');
		}.bind(ref));
	}
});

var CustomHeaderSelectLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			e.preventDefault();
			expID = el.href.substr(el.href.lastIndexOf('/')+1);
			expVal = el.getText();
			$('custom_select_text_header').setProperty('value',expVal);
			$('custom_select_ID_header').setProperty('value',expID);
			$$('.custom_options_header').setStyle('display','none');
		}.bind(ref));
	}
});

var VideoLink = new Class({
	initialize: function(el){
		this.el = el;
		ref = this;
		el.addEvent('click', function (e) {
			e = new Event(e);
			e.preventDefault();
			//href = el.href.substr(el.href.lastIndexOf('/')+1);
			videoLinkClick(el.href);
		}.bind(ref));
	}
});

function toggleTextSize() {
	$('content').getElements('p').each( function (el) {
		el.toggleClass('increaseTextSize');
	});
	$('content').getElements('li').each( function (el) {
		el.toggleClass('increaseTextSize');
	});
	$('content').getElements('td').each( function (el) {
		el.toggleClass('increaseTextSize');
	});
	$('content').getElements('h5').each( function (el) {
		el.toggleClass('increaseTextSize');
	});
	$('content').getElements('h6').each( function (el) {
		el.toggleClass('increaseTextSize');
	});
	if(getCookie('fontToggle') == "large") {
		setCookie('fontToggle','small');
	} else {
		setCookie('fontToggle','large');
	}
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/");
}
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
function GoToExpertise(){
    document.location.href=document.getElementById("custom_select_ID_home").value;
    return false;
}

function closeCustomOptionsHome() {
	$$('.custom_options').setStyle('display','none');
	$('custom_select_format').setStyle('visibility','visible');
}


function CheckQueryString(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

window.addEvent('domready', Init);