$(document).ready(function(){

//	if($('.main div.right').hasClass('right')){  //I want a bool
//		var leftHeight = $('.main .left').height();
//  		var rightHeight = $('.main .right').height();
//  		var height = null;
//  		if(leftHeight == null || rightHeight == null){
//		height = $('.main > div').height();
//  	  	} else {
//  	  	  	if(leftHeight > rightHeight)
//  	  	  	{
//  	  	  	  	height = leftHeight;
//  	  	  	}else{
//  	  	  	  	height = rightHeight;
//  	  	  	}
//  	  	}
//  	  	if(height < 500)
//  	  	  	height = 550;
//  	  	//$('.main').css('height',height);
//	}
	
	// find all the input elements with title attributes
	$('input[title!=""]').hint();




	/**
	 * Fonctions pour les popup
	 * 
	 * Permet de crere un popup en faisant un lien
	 * <a href="http://www.othersite.com/url/" />text</a> (usage normal)
	 * Mais creer des liens popup au besoin selon des specifites que l'on veut. Donc, un lien comme ceux ci (genereront...)
	 *   <a href="http://www.othersite.com/url/" rel="popup" />text</a> et aussi
	 *   <a href="http://www.othersite.com/url/" rel="popup standard 800 600" />text</a> (un popup de 800x600 avec toolbars)
	 *   <a href="http://www.othersite.com/url/" rel="popup console 800 600" />text</a> (un popup de 800x600 mais sans toolbars)
	 *   <a href="http://www.othersite.com/url/" rel="popup fullscreen" />text</a> (un popup plein ecran)
	 *   
	 * En plus, ce qui a ete ajoute est la possibilite (avec addImageAtExternalLinks();) de scanner toutes les
	 * href de la page courrante qui ne sont pas interieurs (ou acceptes) et d'y ajouter une image qui dit que c'est
	 * un popup (via le DOM) et qui annonce que ca va ouvrir un site exterieur... bref qui prendrait
	 *  
	 * @author Renoir Boulanger <lunique@renoirboulanger.com>
	 * @author Marc-Andre Bouchard (expert scripting) <reynold.kirby@gmail.com>
	 **/
	function dopopup(e){
	// Source: http://www.accessify.com/features/tutorials/the-perfect-popup/
		//set defaults - if nothing in rel attrib, these will be used
		var t = "fullscreen";
		var w = null;
		var h = null;
		
		//look for parameters
		attribs = this.rel.split(" ");
		if (attribs[1]!=null) {t = attribs[1];}
		if (attribs[2]!=null) {w = attribs[2];}
		if (attribs[3]!=null) {h = attribs[3];}
		
		//call the popup script
		popUpWin(this.href,t,w,h);
		
		//cancel the default link action if pop-up activated
		if (window.event) {
			window.event.returnValue = false;
			window.event.cancelBubble = true;
		} else if (e) {
			e.stopPropagation();
			e.preventDefault();
		}
	}

	function popUpWin(url, type, strWidth, strHeight){
		closeWin(); 
		//calls function to close pop-up if already open, 
		//to ensure it's re-opened every time, retainining focus
			
		type = type.toLowerCase();
			
		if (type == "fullscreen"){
			strWidth = screen.availWidth;
			strHeight = screen.availHeight;
		}
		var tools="";
		if (type == "standard") 
			tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
		if (type == "console" || type == "fullscreen") 
			tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";

		newWindow = window.open(url, 'newWin', tools);
		
		newWindow.focus();
	}
	var newWindow = null;

	function closeWin(){
		if (newWindow != null){
			if(!newWindow.closed)
				newWindow.close();
		}
	}


	function addImageAtExternalLinks(){
		var anchorList = document.getElementsByTagName('a');

		for(var i=0; i < anchorList.length; i++) {
			if(anchorList[i].href.length > 0 && 
			   anchorList[i].href.indexOf('marioboies') == -1 &&
                           anchorList[i].href.indexOf('piecesanglaisesboies') == -1 &&
                           anchorList[i].href.indexOf('piece-auto-anglaise') == -1 && 
			   anchorList[i].href.indexOf('javascript') == -1 && 
			   anchorList[i].href.indexOf('#') != 0) {
				 var elContainer = anchorList[i];
				 var createdEl = document.createElement('img');
				 createdEl.alt = ' Ce lien ouvrira dans une nouvelle fenêtre.';
				 createdEl.src = '/images/popup_icon.gif';
				 createdEl.className = 'popupIcon';
				 elContainer.setAttribute('rel','popup');
				 elContainer.appendChild(createdEl);
				 elContainer.onclick = dopopup;
			}
		}
	}
	addImageAtExternalLinks();        
});
