﻿
	var thumbW;
	var thumbH;
	
	function setThumbSizes(width,height){
		thumbW = width;
		thumbH = height;
	}
	var loc = String(window.location);
	var page_loc = loc.substring(0,loc.lastIndexOf('/')+1);
	
	/**
	* A simple JavaScript image loaderimage loader
	* @author Cuong Tham
	* @url http://thecodecentral.com/2008/02/21/a-useful-javascript-image-loader
	* @usage
	* var loader = new ImageLoader('IMAGE_URL');
	* //set event handler
	* loader.loadEvent = function(url, image){
	*   //action to perform when the image is loaded
	*   document.body.appendChild(image);
	* }
	* loader.load();
	*/
	var ImageLoader = function(){
	  this.url = null;
	  this.image = null;
	  this.loadEvent = null;
	};

	ImageLoader.prototype = {
	  load:function(url,tag_name){
		this.image = document[tag_name];
		this.url = url;
		var image = this.image;
		var loadEvent = this.loadEvent;
		addListener(this.image, 'load', function(e){
		  if(loadEvent != null){
			loadEvent(url, image);
		  }
		}, false);
		this.image.src = this.url;
	  },
	  getImage:function(){
		return this.image;
	  }
	};
	
	var loader = new ImageLoader();
	loader.loadEvent = function(url, image){
		image.style.cursor='pointer';
		document.body.style.cursor='default';
	}
	function toggle_image_size(tag_name, first_img, second_img){
		document[tag_name].style.cursor='progress';
		document.body.style.cursor='progress';
		var cur_src = document[tag_name].src;
		if(unescape(cur_src) == page_loc + first_img){
			loader.load(second_img,tag_name);
		}else{
			loader.load(first_img,tag_name);
		}
	}
	//source: http://snipplr.com/view.php?codeview&id=561
	// Cross-browser implementation of element.addEventListener()
	function addListener(element, type, expression, bubbling)
	{
	  bubbling = bubbling || false;
	  if(window.addEventListener)	{ // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	  } else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	  } else return false;
	}

	/* swf resizing */
	var swfar = new Array();
	function swfSize(id,scaledUp) {
		id = String(id);
		var swfEl = document.getElementById(id);
		if(swfar[id] == undefined){
			swfar[id] = getDim(swfEl);		
		}
		//alert('gw: ' + swfar[id][0] + '\ngh:' + swfar[id][1]+' tw: '+swfar[id][2]+' th: '+swfar[id][3]);
		document.getElementById(id).style.width = (scaledUp)?swfar[id][2]+'px':swfar[id][0]+'px';
		document.getElementById(id).style.height = (scaledUp)?swfar[id][3]+'px':swfar[id][1]+'px';
	}
	function getThumbProportion(w,h){
		if(w>h){return [thumbW,(thumbW/w)*h]}
		else{return [(thumbH/h)*w,thumbH]}
	}
	function getDim (el) {  
		if (document.all) {
			gh = el.offsetHeight+10;
			gw = el.offsetWidth+10;
		}
		else {
			gh = el.offsetHeight;
			gw = el.offsetWidth;
		}
		var tp = getThumbProportion(gw,gh);
		return [gw,gh,tp[0],tp[1]];
	}
	function setFlashWidth(divid, newW){
		document.getElementById(divid).style.width = newW+"px";
	}
	function setFlashHeight(divid, newH){
		document.getElementById(divid).style.height = newH+"px";		
	}
	function setFlashSize(divid, newW, newH){
		setFlashWidth(divid, newW);
		setFlashHeight(divid, newH);
		
	}
	function canResizeFlash(){
		var ua = navigator.userAgent.toLowerCase();
		var opera = ua.indexOf("opera");
		if( document.getElementById ){
			if(opera == -1) return true;
			else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
		}
		return false;
	}
	
	


