// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i in params)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}


var Slider = new Class({

	options: {
		onChange: Class.empty,
		onComplete: Class.empty,
		onTick: function(pos){
			this.knob.setStyle(this.p, pos);
		},
		mode: 'horizontal',
		steps: 100,
		offset: 0
	},

	initialize: function(el, knob, options){
		this.element = $(el);
		this.knob = $(knob);
		this.setOptions(options);
		this.previousChange = -1;
		this.previousEnd = -1;
		this.step = -1;
		this.element.addEvent('mousedown', this.clickedElement.bindWithEvent(this));
		var mod, offset;
		switch(this.options.mode){
			case 'horizontal':
				this.z = 'x';
				this.p = 'left';
				mod = {'x': 'left', 'y': false};
				offset = 'offsetWidth';
				break;
			case 'vertical':
				this.z = 'y';
				this.p = 'top';
				mod = {'x': false, 'y': 'top'};
				offset = 'offsetHeight';
		}
		this.max = this.element[offset] - this.knob[offset] + (this.options.offset * 2);
		this.half = this.knob[offset]/2;
		this.getPos = this.element['get' + this.p.capitalize()].bind(this.element);
		this.knob.setStyle('position', 'relative').setStyle(this.p, - this.options.offset);
		var lim = {};
		lim[this.z] = [- this.options.offset, this.max - this.options.offset];
		this.drag = new Drag.Base(this.knob, {
			limit: lim,
			modifiers: mod,
			snap: 0,
			onStart: function(){
				this.draggedKnob();
			}.bind(this),
			onDrag: function(){
				this.draggedKnob();
			}.bind(this),
			onComplete: function(){
				this.draggedKnob();
				this.end();
			}.bind(this)
		});
		if (this.options.initialize) this.options.initialize.call(this);
	},

	/*
	Property: set
		The slider will get the step you pass.

	Arguments:
		step - one integer
	*/

	set: function(step){
		this.step = step.limit(0, this.options.steps);
		this.checkStep();
		this.end();
		this.fireEvent('onTick', this.toPosition(this.step));
		return this;
	},

	clickedElement: function(event){
		var position = event.page[this.z] - this.getPos() - this.half;
		position = position.limit(-this.options.offset, this.max -this.options.offset);
		this.step = this.toStep(position);
		this.checkStep();
		this.end();
		this.fireEvent('onTick', position);
	},

	draggedKnob: function(){
		this.step = this.toStep(this.drag.value.now[this.z]);
		this.checkStep();
	},

	checkStep: function(){
		if (this.previousChange != this.step){
			this.previousChange = this.step;
		//	alert(this.step);
			this.fireEvent('onChange', this.step);
		}
	},

	end: function(){
		if (this.previousEnd !== this.step){
			this.previousEnd = this.step;
			this.fireEvent('onComplete', this.step + '');
		}
	},

	toStep: function(position){
		return Math.round((position + this.options.offset) / this.max * this.options.steps);
	},

	toPosition: function(step){
		return this.max * step / this.options.steps;
	}

});

Slider.implement(new Events);
Slider.implement(new Options);

var Drag = {};

Drag.Base = new Class({

	options: {
		handle: false,
		unit: 'px',
		onStart: Class.empty,
		onBeforeStart: Class.empty,
		onComplete: Class.empty,
		onSnap: Class.empty,
		onDrag: Class.empty,
		limit: false,
		modifiers: {x: 'left', y: 'top'},
		grid: false,
		snap: 6
	},

	initialize: function(el, options){
		this.setOptions(options);
		this.element = $(el);
		this.handle = $(this.options.handle) || this.element;
		this.mouse = {'now': {}, 'pos': {}};
		this.value = {'start': {}, 'now': {}};
		this.bound = {
			'start': this.start.bindWithEvent(this),
			'check': this.check.bindWithEvent(this),
			'drag': this.drag.bindWithEvent(this),
			'stop': this.stop.bind(this)
		};
		this.attach();
		if (this.options.initialize) this.options.initialize.call(this);
	},

	attach: function(){
		this.handle.addEvent('mousedown', this.bound.start);
		return this;
	},

	detach: function(){
		this.handle.removeEvent('mousedown', this.bound.start);
		return this;
	},

	start: function(event){
		this.fireEvent('onBeforeStart', this.element);
		this.mouse.start = event.page;
		var limit = this.options.limit;
		this.limit = {'x': [], 'y': []};
		for (var z in this.options.modifiers){
			if (!this.options.modifiers[z]) continue;
			this.value.now[z] = this.element.getStyle(this.options.modifiers[z]).toInt();
			this.mouse.pos[z] = event.page[z] - this.value.now[z];
			if (limit && limit[z]){
				for (var i = 0; i < 2; i++){
					if ($chk(limit[z][i])) this.limit[z][i] = ($type(limit[z][i]) == 'function') ? limit[z][i]() : limit[z][i];
				}
			}
		}
		if ($type(this.options.grid) == 'number') this.options.grid = {'x': this.options.grid, 'y': this.options.grid};
		document.addListener('mousemove', this.bound.check);
		document.addListener('mouseup', this.bound.stop);
		this.fireEvent('onStart', this.element);
		event.stop();
	},

	check: function(event){
		var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2)));
		if (distance > this.options.snap){
			document.removeListener('mousemove', this.bound.check);
			document.addListener('mousemove', this.bound.drag);
			this.drag(event);
			this.fireEvent('onSnap', this.element);
		}
		event.stop();
	},

	drag: function(event){
		this.out = false;
		this.mouse.now = event.page;
		for (var z in this.options.modifiers){
			if (!this.options.modifiers[z]) continue;
			this.value.now[z] = this.mouse.now[z] - this.mouse.pos[z];
			if (this.limit[z]){
				if ($chk(this.limit[z][1]) && (this.value.now[z] > this.limit[z][1])){
					this.value.now[z] = this.limit[z][1];
					this.out = true;
				} else if ($chk(this.limit[z][0]) && (this.value.now[z] < this.limit[z][0])){
					this.value.now[z] = this.limit[z][0];
					this.out = true;
				}
			}
			if (this.options.grid[z]) this.value.now[z] -= (this.value.now[z] % this.options.grid[z]);
			this.element.setStyle(this.options.modifiers[z], this.value.now[z] + this.options.unit);
		}
		this.fireEvent('onDrag', this.element);
		event.stop();
	},

	stop: function(){
		document.removeListener('mousemove', this.bound.check);
		document.removeListener('mousemove', this.bound.drag);
		document.removeListener('mouseup', this.bound.stop);
		this.fireEvent('onComplete', this.element);
	}

});

Drag.Base.implement(new Events, new Options);
Element.extend({
	makeResizable: function(options){
		return new Drag.Base(this, $merge({modifiers: {x: 'width', y: 'height'}}, options));
	}

});

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

function fixPNG(element)
{
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
	var src;

	if (element.tagName=='IMG')
	{
	  if (/\.png$/.test(element.src))
	  {
		src = element.src;
		element.src = "/i/blank.gif";
	  }
		else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
	  }
	}
	else
	{
	  src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
	  if (src)
	  {
		src = src[1];
		element.runtimeStyle.backgroundImage="none";
	  }
	}
	if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}  

var ua = null;
switch(true)
{
	case navigator.userAgent.indexOf("Opera")>-1 :
		ua = "O";
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove = function(e){mouseX = e.pageX; mouseY = e.pageY};
		break;
	case navigator.userAgent.indexOf("MSIE")>-1 :
		ua = "IE";
		break;
	case navigator.userAgent.indexOf("Gecko")>-1 :
		ua = "FF";
		window.captureEvents(Event.MOUSEMOVE);
		window.onmousemove = function(e){mouseX = e.pageX; mouseY = e.pageY};
		break;
}

function gE(id)
{
	return document.getElementById(id);
}

String.prototype.isEmail = function () { 
	return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(this);
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=")
		
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
				return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return ""
}

function tlocation(loc, time, l)
{
	if (l)
	{
		window.location = loc;
	}
	else
	{
		window.setTimeout('tlocation("'+loc+'", 0, true)', time);
	}
}

function CookieMoe(hardlocate, set)
{
	var i = Cookie.get('disc-times') ? parseInt(Cookie.get('disc-times')) : 0;
	Cookie.set('disc-times', (set ? set :(i+1)), {duration: 15});
	if (i > 3 && hardlocate)
	{
		window.location = '/';
	}

	return i;
}

function toHome()
{
	window.location = '/';
}

var discval = $random(3, 9);

function goDiscount()
{

	if (!getCookie('disc-times'))
	{
		//window.location = '/discount.html';
		QS.navigate('discount');
		
		var so = new SWFObject("i/discount.swf?percent="+discval+"%25","jocker","380","320","8","#000");
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess","always");
		so.write("dflash");

		CookieMoe();
	}
	else
	{
		QS.navigate('already-have-discount');		
	}

}

function onLoad()
{
	if (Cookie.get('disc-input')==1)
	{
		try
		{
			document.getElementById('disc-field').style.display = 'block';	
		}
		catch (e)
		{
		}
	}
}


var Discount = {

	doneT : function()
	{
		window.setTimeout("Discount.done()", 2500);
	},

	done : function()
	{
		if (CookieMoe() >= 3) 
		{				
			window.setTimeout("Discount.showForm()", 3000);
		}
		else
		{
			document.getElementById('button-section').style.display = 'block';
		}
	},

	showForm : function()
	{
		document.getElementById('button-section').style.display = 'none';
		document.getElementById('dform').style.display = 'block';
		document.getElementById('dflash').style.display = 'none';
	}
}

var Tape = {	

	speedHoriz:		75, // 1/x
	speedVert:			65, // 1/x

	boxTop:				new Array(),
	boxLeft:				new Array(),
	boxTimer:			new Array(),
	boxWidth:			new Array(),
	boxBodyWidth:	new Array(),
	boxHeight:			new Array(),
	boxBodyHeight:	new Array(),

	currSet : null,		// debug

	runHoriz : function(id, direction, stop) // direction == 1 -- right
	{
		pid = this.getPrimaryId(id);
		if (!direction) direction = 0;
		if (!stop) stop = 0;

		//-
		if (!this.boxLeft[pid]) this.boxLeft[pid] = 0;
		this.boxWidth[pid]			= gE(pid + "_ul").clientWidth;
		this.boxBodyWidth[pid]	= gE(pid + "_body").clientWidth;
		//-
//gE("123123").innerHTML = Math.abs(this.boxLeft[pid]);		
		var f = false;
		f =  !direction ? Math.abs(this.boxLeft[pid])>this.boxWidth[pid]-this.boxBodyWidth[pid] : this.boxLeft[pid] == 0;

		if(f || stop)
		{
			clearTimeout(this.boxTimer[pid]);
			return;
		}

		if (direction == 1)
		{
			var delta = Math.round(Math.abs(this.boxLeft[pid])/50);		
			delta = delta == 0 ? 1 : delta;
			delta = delta > 20 ? 20 : delta;
			this.boxLeft[pid] += delta;
		}
		else
		{
			var delta = Math.round((this.boxWidth[pid]-this.boxBodyWidth[pid]-Math.abs(this.boxLeft[pid]))/50);		
			if (ua != "IE") delta = this.boxWidth[pid]-this.boxBodyWidth[pid]-Math.abs(this.boxLeft[pid]) != 0 && delta == 0 ? 1 : delta;
			delta = delta > 20 ? 20 : delta;
			this.boxLeft[pid] -= delta;
		}
//$('speed').innerHTML = delta;
		gE(pid + "_ul").style.left = this.boxLeft[pid]+"px";
		this.boxTimer[pid] = setTimeout("Tape.runHoriz('" + id + "', " + direction + ", " + stop + ")", 20 - Math.round(10*(1/delta)) );
	},

	runVert : function(id, direction, stop) // direction == 1 -- down
	{
		pid = this.getPrimaryId(id);
		if (!direction) direction = 0;
		if (!stop) stop = 0;

		//-
		if (!this.boxTop[pid]) this.boxTop[pid] = 0;
		this.boxHeight[pid]			= gE(pid + "_ul").clientHeight;
		this.boxBodyHeight[pid]	= gE(pid + "_body").clientHeight;
		//-
//gE("123123").innerHTML = this.boxTop[pid];		
		var f = false;
		f =  !direction ? Math.abs(this.boxTop[pid])>this.boxHeight[pid]-this.boxBodyHeight[pid] : this.boxTop[pid] == 0;

		if(f || stop)
		{
			clearTimeout(this.boxTimer[pid]);
			return;
		}

		if (direction == 1)
		{
			var delta = Math.round(Math.abs(this.boxTop[pid])/10);		
			delta = delta == 0 ? 1 : delta;
			this.boxTop[pid] += delta;
		}
		else
		{
			var delta = Math.round((this.boxHeight[pid]-this.boxBodyHeight[pid]-Math.abs(this.boxTop[pid]))/10);		
			/*if (ua != "IE")*/ delta = this.boxHeight[pid]-this.boxBodyHeight[pid]-Math.abs(this.boxTop[pid]) != 0 && delta == 0 ? 1 : delta;
			this.boxTop[pid] -= delta;
		}

		gE(pid + "_ul").style.top = this.boxTop[pid]+"px";
		this.boxTimer[pid] = setTimeout("Tape.runVert('" + id + "', " + direction + ", " + stop + ")", this.speedVert - Math.round((1/delta) * 40));
	},

	runLeft : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id);
	},

	runLeftStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id, 0, 1);
	},

	runRight : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id, 1);
	},

	runRightStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runHoriz(id, 1, 1);
	},

	runUp : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id);
	},

	runUpStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id, 0, 1);
	},

	runDown : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id, 1);
	},

	runDownStop : function(id)
	{
		pid = this.getPrimaryId(id);
		this.runVert(id, 1, 1);
	},

	getPrimaryId: function(id)
	{
		var re = new RegExp("\_[^_]+$","ig");
		id = id.replace(re, '');
		
		return id;
	},

	initCategory :function()
	{
	//	debugger;
		var sel = $('select-group');
		for(var j in Templates)
		{
			var o = new Element("option");
			o.innerHTML = o.value = j;
			o.injectInside(sel);
		}
	}, 

	init :function(set)
	{
//		debugger;
		gE('bottom-tape_ul').style.left='0px';
		this.boxLeft = [];
		// --
		this.set = set;
		$("bottom-tape_ul").innerHTML="";
		var width = 0;

		var obj = Templates[Tape.set][0];

		if(!Order.orderID)
			Order.orderID=obj[0];
		$("solDesign").src=Order.img="designs/"+set+"/big/"+obj[0]+".jpg";
		$("solDesign2").src=$("solDesign").src.replace(".jpg", "-2.jpg");

		for(var i=0;i<Templates[set].length;i++)
		{
			var li = new Element("li");
			var img = new Element("img");
			var imgL = new Element("img");

			img.onclick = function()
			{
						//alert(this.id);

				$("solDesign").src=Order.img=this.src.replace("small", "big");
				$("solDesign2").src=$("solDesign").src.replace(".jpg", "-2.jpg");
				var id=parseInt(this.id.replace("thumb", ""));
				var obj = Templates[Tape.set][id];
				Order.orderID=obj[0];
				Order.orderPrice=parseInt(obj[2]);
				Order.defaultModules=obj[3];
			}
/*
			img.onload = function()
			{
		//		debugger;

				if (this.title == 'preview')
				{
					this.style.display = 'block';
					var id = parseInt(this.id.replace('thumb', ''))+1;

					if ($("thumb"+id))
					{
						$("thumb"+id).src = $("thumb"+id).alt;				
						$("thumb"+id).title	= 'preview';		
					//	$("thumb"+id).alt		= '';		
					}
				}; 
			}
*/
			imgL.src = "i/ajax-loader.gif";
			imgL.className ="a-loader";
			imgL.injectInside(li);
//debugger;
//alert(i);
	//		if (i==0)
			{
				img.src = "designs/"+set+"/small/"+Templates[set][i][1];
				img.title	= 'preview';
			}
	/*		else
			{
				img.src	= "i/pix.gif";
				img.alt	= "designs/"+set+"/small/"+Templates[set][i][1];
				img.title	= '';
			}
	*/
			img.id="thumb"+i;
			img.style.display = "block";
			img.className ="i";
			img.injectInside(li);

			li.injectInside("bottom-tape_ul");

			width += 102;
		}

		$("bottom-tape_ul").style.width = width + 'px';
		Order.orderPrice=parseInt(obj[2]);
		Order.defaultModules=obj[3];
	},

	showMain : function()
	{
		var src = $("solDesign").src;
		src = src.replace("-2.jpg", ".jpg");
		src = src.replace("-2.gif", ".gif");
		$("solDesign").src = src;
	},

	showInner : function()
	{
		var src = $("solDesign").src;
		src = src.replace(".jpg", "-2.jpg");
		src = src.replace(".gif", "-2.gif");
		$("solDesign").src = src;
	}
}