// init function called on load
function init() {

}

var True_story = Class.create({
	initialize: function(elm_id, regular_image, sepia_image, hero_image, name, description) {
    	this.me = $(elm_id);
		this.img = $(elm_id+'img');
		this.regular_image = regular_image;
		this.sepia_image = sepia_image;
		this.hero_image = hero_image;
		this.name = name;
		this.description = description;
		this.tsImage = $("tsImage");
		this.tsTitle = $("tsTitle");
		this.tsDesc = $("tsDesc");
		this.tsDefaultImage = $("tsImage").innerHTML;
		this.tsDefaultTitle = $("tsTitle").innerHTML;
		this.tsDefaultDesc = $("tsDesc").innerHTML;
		Event.observe(
			this.me,
			"mouseover",
			this.rollOver.bindAsEventListener(this)
		);
		Event.observe(
			this.me,
			"mouseout",
			this.rollOut.bindAsEventListener(this)
		);
		this.preload();
  	},
  	preload:function(){
		var im1 = new Image();
		im1.src = this.regular_image;
		var im2 = new Image();
		im2.src = this.sepia_image;
		var im3 = new Image();
		im3.src = this.hero_image;
	},
	rollOver: function(event){
		this.replaceHero();
		this.img.src = this.regular_image;
	},
	rollOut: function(event){
		this.restoreHero();
		this.img.src = this.sepia_image;
	},
	replaceHero: function(){
		this.tsImage.innerHTML = '<a href=""><img src="'+this.hero_image+'" border="0"></a>';
		this.tsTitle.innerHTML = '<a href=""><span class="boldText">'+this.name+'</span></a>';
		this.tsDesc.innerHTML = this.description;
	},
	restoreHero: function(){
		this.tsImage.innerHTML = this.tsDefaultImage;
		this.tsTitle.innerHTML = this.tsDefaultTitle;
		this.tsDesc.innerHTML = this.tsDefaultDesc;
	}
});

//var m = new Simple_True_Story({elm_id: 'tsThumb1', regular_image: 'image1.jpg', sepia_image: 'image_s.jpg'});
var Simple_True_Story = Class.create({
	//elm_id, regular_image, sepia_image
	initialize: function(elm_obj) {
		this.id = elm_obj.elm_id;
    	this.me = $(this.id);
		this.img = $(this.id+'img');
		this.regular_image = elm_obj.regular_image;
		this.sepia_image = elm_obj.sepia_image;
		Event.observe(
			this.me,
			"mouseover",
			this.rollOver.bindAsEventListener(this)
		);
		Event.observe(
			this.me,
			"mouseout",
			this.rollOut.bindAsEventListener(this)
		);
		this.preload();
  	},
  	preload:function(){
		var im1 = new Image();
		im1.src = this.regular_image;
		var im2 = new Image();
		im2.src = this.sepia_image;
	},
	rollOver: function(event){
		this.img.src = this.regular_image;
	},
	rollOut: function(event){
		this.img.src = this.sepia_image;
	}
});



Event.observe(window,'load',monitorShareItLink);

function monitorShareItLink() {
	if($('shareit_link')){
		var shareItLink = $('shareit_link');
		Event.observe(shareItLink, 'click', function() {
			var shareit = $('shareit');
			if(!shareit || shareit == null) {
				var body = $('body');
				//var shareitdiv = document.createElement('div');
				var shareitdiv = Builder.node('div', {id: 'shareit'},[
					Builder.node('img', {src: base_url+"public/images/layout/loading.gif"})
				]);
				//shareitdiv.setAttribute('id','shareit');
				//shareitdiv.innerHTML='<img src=base_url+"images/layout/loading.gif" />';
				body.appendChild(shareitdiv);
				
				/*Element.clonePosition(shareitdiv, $('shareit_link'),{
					setLeft: 	true,
					setTop: 	true,
					setWidth: 	false,
					setHeight: 	false,
					offsetLeft: -480,
					offsetTop: 	-350
				});*/

				// loads the wrong page if you remove the slash
				// on systems where site is not docroot, with
				// the slash == 404 page
				new Draggable(shareitdiv, {});
				new Ajax.Updater('shareit', base_url+'shareit', { evalScripts: true, parameters: {link: location.href } });
			}else{
				shareit.remove();
			}
		});
	}
}
/*
function bottom_nav_rollover(event){
	elm = $(event.element());
	elm.cleanWhitespace();
	par = $(elm.up('div.structureFunction').firstDescendant());
	par.toggleClassName('hover_state');
	//alert(par.className);
}
*/
function close_shareit(){
	$('shareit').remove();
}

function PrintThisPage(title_m) { 
	/*title = title_m || "New Chapter®";

	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
	sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 

	var sWinHTML = document.getElementById('content').innerHTML; 

	var winprint=window.open("","",sOption); 
	winprint.document.open(); 
	winprint.document.write('<html>');
	winprint.document.write('<head>');
	winprint.document.write('<title>');
	winprint.document.write(title);
	winprint.document.write('</title>');
	css = $$('link');
	for(x=0; x<css.length; x++){
		winprint.document.write('<link rel="stylesheet" type="text/css" href="'+css[x].href+'" media="'+css[x].media+'" />');
	}
	winprint.document.write('<link rel="stylesheet" type="text/css" href="'+base_url+'public/styles/printlayout.css"/>');
	winprint.document.write('</head>');
	winprint.document.write('<body class="printerStyle"><div id="printerContent">');
	winprint.document.write(sWinHTML);          
	winprint.document.write('</div></body></html>'); 
	winprint.document.close(); 
	winprint.focus(); 
	winprint.print();*/
	window.focus();
	window.print();
}