function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}

function loadjscssfile(filename, filetype){
    if (filetype=="js"){ //if filename is a external JavaScript file
        var fileref=document.createElement('script');
        fileref.setAttribute("type","text/javascript");
        fileref.src = filename;
    }
    else if (filetype=="css"){ //if filename is an external CSS file
        var fileref=document.createElement("link");
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.href = filename;
    }
    document.getElementsByTagName("head")[0].appendChild(fileref);
}

function prependElement(parentID,child){
     var parent = document.getElementById(parentID);
     parent.insertBefore(child,parent.childNodes[0]);
}

function get_Slides(data){
		var innerSlide = document.createElement('ul');
		var zePosts = data.entries;
		var j = 0;
		for (var i = 0; i < 20; i++){
			if (j < 4){
				var zePost = zePosts[i];
				if (!zePost || !zePost.embeddedImageLinks[0] || !zePost.embeddedImageLinks[0].urlTemplate){}
				else{
				// preparing the slide
				var o_picture = zePost.embeddedImageLinks[0].urlTemplate.replace("{spec}", "640wi");
				var o_li = document.createElement('li');
				o_li.innerHTML = '<img src="'+ o_picture +'" /></a>';
				// preparing the label    
				var o_permalink = zePost.permalinkUrl;
				var o_title = zePost.title;
				var o_div = document.createElement('div');
				if (j == 0) {o_div.className = "control_active";}else{o_div.className = "control_inactive";}
				o_div.innerHTML = '<h2><a href="'+ o_permalink +'">'+ o_title +'</a></h2>';
				innerSlide.appendChild(o_li);
				// appending slides
				document.getElementById('container_slideshow').appendChild(innerSlide);			    
				// appending controls			    
				document.getElementById('control_wrap').appendChild(o_div);
				j++;
				}
			}
		}
		slider_typepad();
}


function append_Slideshow(contentDiv, contentTitle){
	// attach the slider CSS before the TypePad one to enable overload
	var theCSS = document.createElement('link');
        theCSS.setAttribute("rel", "stylesheet");
        theCSS.setAttribute("type", "text/css");
	theCSS.href = 'http://www.typepad.fr/includes/css/slider_css.css';
	var theHead = document.getElementsByTagName('head')[0];
	theHead.insertBefore(theCSS,theHead.childNodes[0]);	
	// create the basic structure for the slideshow
	var theSlides= document.createElement('div');
	theSlides.id = 'container_slideshow';
	var theControls = document.createElement('div');
	theControls.id = 'control_wrap';
	// create the wrapper
	var ele=document.createElement("div");
	ele.id = "slideshow_wrap";
	var wrapper_width = document.getElementById(contentDiv).offsetWidth;
	ele.style.cssText = "width: "+ wrapper_width +"px";
	ele.appendChild(theSlides);
	ele.appendChild(theControls);
	prependElement(contentDiv,ele);
	if (contentTitle){
		// create the title
		var theTitle = document.createElement('h3');
		theTitle.className = "entry-header";
		theTitle.className += " entry-slider";		
		theTitle.innerHTML = contentTitle;
		prependElement(contentDiv, theTitle);		
	}	
}
function init_Slider(contentDiv, contentTitle){
	append_Slideshow(contentDiv, contentTitle);
	//loadjscssfile("http://www.typepad.fr/includes/css/slider_css.css", "css");
	loadjscssfile("http://www.typepad.fr/includes/scripts/slider_func.js", "js");
}
function slider_typepad(){
var slider_width = document.getElementById('slideshow_wrap').offsetWidth;
var options = {
	"id":		'container_slideshow',
	"width":	slider_width,
	"height":	279,
	"delay":	5000,
	"speed":	200,
	"steps":	4,
	"onstart":	function(c,l){
					c_div= document.getElementById('control_wrap');
					divs=c_div.getElementsByTagName('div');
					divs[l].className='control_inactive';
					divs[c].className='control_active';
				}
};		
var ss= new slidein(options);
ss.st();
var c_divs= document.getElementById('control_wrap');
c_divs.style.position="relative";
c_divs.style.top=-(options.height)+"px";
c_divs.style.left="0px";
c_divs.style.zIndex=10000;

var divss=c_divs.getElementsByTagName('div');
for(i=0;i<divss.length;i++){
	divss[i].num=i;
	divss[i].onclick=function(){ss.gt(this.num+1);};
}
ss.ti=setTimeout(ss.pl,ss.del);
}


