/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Benoit Asselin | http://www.ab-d.fr */

function rotate(p_deg) {
	if(document.getElementById('canvas')) {
		/*
		Ok!: Firefox 2, Safari 3, Opera 9.5b2
		No: Opera 9.27
		*/
		var image = document.getElementById('image');
		var canvas = document.getElementById('canvas');
		var canvasContext = canvas.getContext('2d');
		
		switch(p_deg) {
			default :
			case 0 :
				canvas.setAttribute('width', image.width);
				canvas.setAttribute('height', image.height);
				canvasContext.rotate(p_deg * Math.PI / 180);
				canvasContext.drawImage(image, 4, 10);
				break;

		};
		
	};
};


// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
	var image = document.getElementById('image');
	var canvas = document.getElementById('canvas');
	if(canvas.getContext) {
		image.style.visibility = 'hidden';
		image.style.position = 'absolute';
		image.style.width = '240px'
		image.style.height = '240px'
	} else {
		canvas.parentNode.removeChild(canvas);
	};
	
	rotate(-2.25);
});




var tmp = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
if(tmp) var isIE = document.namespaces ? 1 : 0;

if(isIE) {
	if(document.namespaces['v'] == null) {
		var stl = document.createStyleSheet();
		stl.addRule("v\\:*", "behavior: url(#default#VML);"); 
		document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); 
	}
}

function getImages(className){
	var children = document.getElementsByTagName('img'); 
	var elements = new Array(); var i = 0;
	var child; var classNames; var j = 0;
	for (i=0;i<children.length;i++) {
		child = children[i];
		classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}
function getClasses(classes,string){
	var temp = '';
	for (var j=0;j<classes.length;j++) {
		if (classes[j] != string) {
			if (temp) {
				temp += ' '
			}
			temp += classes[j];
		}
	}
	return temp;
}
function getClassValue(classes,string){
	var temp = 0; var pos = string.length;
	for (var j=0;j<classes.length;j++) {
		if (classes[j].indexOf(string) == 0) {
			temp = Math.min(classes[j].substring(pos),100);
			break;
		}
	}
	return Math.max(0,temp);
}
function getClassAttribute(classes,string){
	var temp = 0; var pos = string.length;
	for (var j=0;j<classes.length;j++) {
		if (classes[j].indexOf(string) == 0) {
			temp = 1; 
			break;
		}
	}
	return temp;
}

function addIEInstant() {
	var theimages = getImages('instant');
	var image; var object; var vml; var display;
	var itiltleft;
	var preserve, head, foot, fill;
	var classes = ''; var newClasses = ''; var path, historical, nocorner;
	var inset = 6; var i, f, r, db, hz, flt, ww, hh, ff, yo, xo;
	for(i=0;i<theimages.length;i++) {
		image = theimages[i]; object = image.parentNode; historical = 0;
		preserve = 0; 
		itiltleft = 0;
		if(image.width>=64 && image.height>=64) {
			classes = image.className.split(' ');
			itiltleft = getClassAttribute(classes,"itiltleft");
			preserve = getClassAttribute(classes,"preserve");
			if(itiltleft==true) tilt = 'l';
			newClasses = getClasses(classes,"instant");
			width = image.width; height = image.height;
			border = Math.round(((width+height)/2)*0.00); db=border;
			offset = border/2; inset = parseInt(offset*.75);
			ww=width-(border*2); hh=height-(border*2); hz=Math.round(hh/3);
			if(tilt=='l') {
				rotation = -2.08; scale = 0.98; tilt = 'r';
			}
			display = (image.currentStyle.display.toLowerCase()=='block')?'block':'inline-block';        
			vml = document.createElement(['<var style="zoom:1;overflow:hidden;display:' + display + ';width:' + width + 'px;height:' + height + 'px;padding:0;">'].join(''));
			head = '<v:group style="rotation:' + rotation + '; zoom:' + scale + '; display:' + display + '; margin:10px 0 0 0; padding:0; position:relative; left:6px; width:215px;height:215px;" coordsize="'+width+','+height+'"><v:rect strokeweight="0" filled="f" stroked="f" fillcolor="transparent" style="zoom:1;margin: 0;padding: 0;display:block;position:absolute;top:0px;left:0px;width:'+width+'px;height:'+height+';"><v:fill opacity="0" color="#FFFFFF" /></v:rect>';
			fill = '<v:image src="' + image.src + '" style="zoom:1;margin: 0;padding: 0;display:block;position:absolute;top:' + border + 'px;left:' + border + 'px;width:' + (width-offset-(2*border)) + 'px;height:' + (height-offset-(2*border)) + ';"></v:image>';
			foot = '</v:group>';
			vml.innerHTML = head+fill+foot;
			vml.className = newClasses;
			vml.style.cssText = image.style.cssText;
			vml.style.visibility = 'visible';
			vml.src = image.src; vml.alt = image.alt;
			vml.width = image.width; vml.height = image.height;
			if(image.id!='') vml.id = image.id;
			if(image.title!='') vml.title = image.title;
			if(image.getAttribute('onclick')!='') vml.setAttribute('onclick',image.getAttribute('onclick'));
			object.replaceChild(vml,image);
		}
	}
}


var instantOnload = window.onload;
window.onload = function () { if(instantOnload) instantOnload(); if(isIE){addIEInstant(); }}