
// ==================================================================
//
// JAVASCRIPT UNEFOIS2.COM
// Stephane Chanay-Savoyen
// http://www.chanaysavoyen.com
//
// ==================================================================

(function(){
	var
	plugin_thickbox=function(){
		
		// rewrite function
		var w=window;
		if( typeof w.TB_template_imageURL=='function' ){
			w.TB_template_imageURL = function(url, imageWidth, imageHeight, caption, img_caption, prev, imageCount, next) {
				var u=unescape;
				return u("%3Cdiv id='TB_hoverNav'")+"style='height:"+imageHeight+"'"+u("%3E")+
				String(prev.html).replace('TB_prev','TB_prev_hoverNav') +
				String(next.html).replace('TB_next','TB_next_hoverNav') +
				u("%3Cimg id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+"'/%3E")+
				u("%3C/div%3E")+
				u("%3Cdiv id='TB_caption' style='position:absolute;width:100%;'%3E")+img_caption+u("%3C/div%3E") + 
				u("%3Cdiv id='TB_secondLine'%3E")+
				u("%3Cspan class='TB_bg' style='display:block;position:absolute;width:100%; text-align:left;'%3E")+
				/*prev.html +" | "+ next.html +" | "+ */
				u("%3Cspan id='TB_count'%3E"+ imageCount +"%3C/span%3E%3C/span%3E") + 
				u("%3Cspan class='TB_bg' style='display:block;position:absolute;width:100%; text-align:right'%3E")+
				u("%3Ca href='#' id='TB_closeWindowButton' title='close'%3E%3Cspan%3EX%3C/span%3E%3C/a%3E%3C/span%3E")+
				u("%3C/div%3E");
			}
		}
	}
	,
	body_background=function(a){
		
		var bg=a||$('body').css("backgroundImage")||"none";
		$('body').css({ backgroundImage:"none" });
		if( bg!="none" ){ 
			bg=bg
			.replace("url('","")
			.replace("url(\"","")
			.replace("url(","")
			.replace("')","")
			.replace("\")","")
			.replace(")",""); 
			var s="<div class='full_background' style='"+
					"position:fixed;width:100%;height:100%;"+
					"overflow:hidden;top:0;left:0;z-index:-1;"+
					"'>"+
				"<img src='"+bg+"'>"+
				"</div>";
			$('body').append(s);
		}	$("body").css({ zIndex: "0" });
		
	}
	,
	// body ready
	ready=function(){
		
		// deal with expanding menu
		var menu=new fun.expandingMenu;
		menu.init("expandingMenu");
		$("#expandingMenu").css({display:"block"});
		
		// deal with thickbox
		plugin_thickbox();
		
		// deal with full image background
		var bg=$('body').css("backgroundImage")||"none";
		$('body').css({ backgroundImage:"none" });
		body_background(bg);
		
	}
	,
	// Lets run
	run=function(){
		
		var style=function(a){
			var d=document,
				h=d.getElementsByTagName("head")[0];
			if( h && typeof d.createElement=="function" ){
				elt = d.createElement("style");
				elt.setAttribute("type","text/css");
				elt.appendChild(d.createTextNode(a));
				//h.insertBefore(elt,h.firstChild);
				h.appendChild(elt);
			}else{ d.write("<style type='text/css'>"+a+"</style>"); }
		};
		
		style("#expandingMenu li{ display:none; }"+
		"#expandingMenu li.section-title{ display:block; }");
		$('body').ready(function(){ready();});
	}
	;
	var w=window; // shortcut

	// Make public container accessible
	w._fun_=w._fun_||function(){};

	// Create private instance
	var fun=new w._fun_();

	// autorun
	run();
	
})();
