//
// Class: generic DOM functions.
// ****************************************************************************
//  author: Casey Flynn
//  usage:  var ntsDOM = new novatexDOM({color: "black"});
//
var novatexDOM = new Class({
	
	//
	// Function: Initalize Novatex DOM class
	// *************************************
	//
	initialize: function(options) {
		this.options = options; //save our opitons.
		

		// always handle external links
		$$('a.external').each(function(link){this.externalLinks(link)},this);
		
		// always handle list Hover
		this.listHover();
		
		// always fix any png files
		$$('img.fixPNG').each(function(png){fixPNG(png)});
		
	},
	
	//
	// Function: Generic externalLinks function.
	// ******************************
	// author: Casey Flynn
	// usage: tenwaysDOM::externalLinks();
	externalLinks: function(myLink) {
		myLink.setProperty('target','_blank');
	},
		
	//
	// Function: fixPNG
	// ****************************************************
	//	this will make transparent pngs show up correctly in IE. This function 
	//	is based almost entirely on the function found here: 
	//	<http://homepage.ntlworld.com/bobosola/pnginfo.htm>
	//
	// Developer notes ::
	// Aaron Newton, <aaron [dot] newton [at] cnet [dot] com>
	//
	fixPNG: function (myImage) 
	{
		try {
			var arVersion = navigator.appVersion.split("MSIE");
			var version = parseFloat(arVersion[1]);
			if ((version >= 5.5) && (version < 7) && (document.body.filters)){
				myImage = $(myImage);
				var vis = myImage.visible();
				if(!vis) myImage.show();
				var width = $(myImage).offsetWidth;
				var height = $(myImage).offsetHeight;
				if(!vis) myImage.hide();
				var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
				var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
				var imgTitle = (myImage.title) ? "title='" + myImage.title	+ "' " : "title='" + myImage.alt + "' ";
				var imgStyle = "display:inline-block;" + myImage.style.cssText;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
										+ " style=\"" + "width:" + width 
										+ "px; height:" + height 
										+ "px;" + imgStyle + ";"
										+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
										+ "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
				myImage.outerHTML = strNewHTML;
			}
		} catch(e) {}
	},

	listHover:function(){
		$$('ul.hover').each(function(e){
			this.overAppend(e,'li');
		},this);
	},
	
	//
	// overAppend: Appends over on tags that don't support hover
	// *********************************************
	// author: casey flynn
	// usage: novatexDOM::handle_over('view_id','TAG');
	//
	overAppend:function (v, t) {
		this.list = $ES(t,v);
		this.list.each(function(e){
			e.addEvent('mouseover', function(event){e.addClass('over');});
            e.addEvent('mouseout', function(event){e.removeClass('over');});
		},this);
	},
	
	//
	// imgFadeSwitch
	// *************************************
	// author: casey flynn
	// usage: novatexDOM.imgFadeSwitch('view_id');
	// notes: view container must have an img tag and at least 1 anchor
	imgFadeSwitch: function(v) {
		this.v = v;
		$ES('a',v).each(function(a){
			a.onclick = function() {
				i = $E('img', this.v);
				i.effect('opacity',{duration: 1000,onComplete:
					function(){
						i.setProperty('src',a.getProperty('href'));
						$E('img', this.v).effect('opacity',{duration: 1000}).custom(0,1);
					}.bind(this)
				}).custom(1,0);
				return false;	
			}.bind(this);
		},this);
	}
});


/*
Script: Swiff.Base.js
	Contains <Swiff.create>, <Swiff.getVersion>

Author:
	Valerio Proietti, <http://mad4milk.net>
	
Credits:
	Flash detection 'borrowed' from SWFObject.

License:
	MIT-style license.
*/

var Swiff = {
	
	count: 0,
	
	callBacks: {},
	
	/*
	Function: Swiff.create
		creates a flash object with supplied parameters.

	Arguments:
		source - the swf path.
		properties - an object with key/value pairs. all options are optional. see below.
		where - the $(element) to inject the flash object.

	Properties:
		width - int, the width of the flash object. defaults to 0.
		height - int, the height of the flash object. defaults to 0.
		onLoad - string, sets a variable in the actionsctipt called onLoad. Used to fire a function when flash is loaded. defaults to none.
		id - string, the id of the flash object. defaults to 'Swiff-Object-num_of_object_inserted'.
		wmode - string, transparent or opaque.
		bgcolor - string, hex value for the movie background color.

	Returns:
		the object element, to be injected somewhere.
	*/
	
	create: function(source, properties, where){
		if (!Swiff.fixed) Swiff.fix();
		var props = Object.extend({
			scale: 'noscale', width: 0, height: 0, onLoad: 'Class.empty', id: 'Swiff-Object-'+Swiff.count++, wmode: 'transparent', bgcolor: ''
		}, properties || {});
		var load = source + '?onLoad=' + props.onLoad;
		var html =
			'<object width="'+props.width+'" height="'+props.height+'" id="'+props.id+'" type="application/x-shockwave-flash" data="'+load+'">'+
				'<param name="allowScriptAccess" value="always" />'+'<param name="movie" value="'+load+'" />'+
				'<param name="bgcolor" value="'+props.bgcolor+'" />'+'<param name="scale" value="'+props.scale+'" />'+
				'<param name="salign" value="lt" />'+'<param name="wmode" value="'+props.wmode+'">'+
			'</object>';
		
		var element = new Element('div').setHTML(html).getElementsByTagName('object')[0];
		if (where) $(where).appendChild(element);
		return element;
	},
	
	//from swfObject, fixes bugs in ie+fp9
	fix: function(){
		
		Swiff.fixed = true;
		
		window.addEvent('beforeunload', function(){
			__flash_unloadHandler = Class.empty;
			__flash_savedUnloadHandler = Class.empty;
		});

		window.addEvent('unload', function(){
			if (!window.ie) return;
			var objects = $each(document.getElementsByTagName("object"), function(swf){
				swf.style.display = 'none';
				for (var p in swf){
					if (typeof swf[p] == 'function') swf[p] = Class.empty;
				}
			});
		});
	},
	
	/*
	Function: Swiff.getVersion
		gets the major version of the flash player installed.

	Returns: 
		a number representing the flash version installed, or 0 if no player is installed.
	*/
	
	getVersion: function(){
		if(navigator.plugins && navigator.mimeTypes.length){
			var x = navigator.plugins["Shockwave Flash"];
			if(x && x.description) var version = x.description;
		} else if (window.ActiveXObject){
			try {
				var x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
				var version = x.GetVariable("$version");
			} catch(e){}
		}
		if (version) return version.replace(/\w+\s+/gi, '').toInt();
		else return 0;
	},
	
	/*
	Function: Swiff.remote
		Calls an ActionScript function from javascript. Requires ExternalInterface.

	Returns: 
		Whatever the ActionScript Returns
	*/
	
	remote: function(object, name){
		var value = object.CallFunction("<invoke name=\"" + name + "\" returntype=\"javascript\">" + __flash__argumentsToXML(arguments, 2) + "</invoke>");
		return eval(value);
	}

};

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
   // window.sidebar.addPanel(title,url,"");
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}