function require(lib) {
	document.write('<script language="javascript" type="text/javascript" src="js/'+lib+'.js"></script>')
}
require('jquery');

//prototype's fabulous bind and $A 
var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0, length = iterable.length; i < length; i++)
      results.push(iterable[i]);
    return results;
  }
}
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}
//


var E = {
	add: function(obj, evt, func) {
		if (document.addEventListener) obj.addEventListener(evt, func, false);
		else if(document.attachEvent) obj.attachEvent('on'+evt,func);
		},
	remove: function(obj, evt, func) {
			obj.removeEventListener(evt, func, false);
		},
	get: function(e, p) {
			var e = e || window.event;
			if (p) E.pd(e);
			return t = e.target || e.srcElement;
		},
	pd: function(e) {
			if (e.stopPropagation) e.stopPropagation();	 
			else if(e.cancelBubble) e.cancelBubble = true;			
			if (e.preventDefault) e.preventDefault();
			else e.returnValue = false; 
	},
	pos: function(e) {
		var left = 0;
		var top  = 0;
		while (e.offsetParent){
			left += e.offsetLeft;
			top  += e.offsetTop;
			e     = e.offsetParent;
		}
		left += e.offsetLeft;
		top  += e.offsetTop;

		return {x:left, y:top};
	}
}




var Req = {
	__GET: {},
	filename: '',
	query_string: location.search || '',
	type: '',
	uri: location.href,
	initialized: false,
	
	init: function() {
		ps = this.uri
				
		this.type = ps.match(/^https?|ftp|file/);		
		ps = ps.replace(/https?:\/\/|file:\/|ftp:\/\//g, '');
		
		ps = ps.split('/');
		psl = ps.length
		 
		ps[psl-1] = ps[psl-1].split('?');
		this.filename = (ps[psl-1].length > 1) ? ps[psl-1].shift() : ps.pop();
		
		params = location.search.slice(1).split('&');
		for (i=0;i<params.length;i++) {
			x = params[i].split('=');
			this.__GET[x[0]] = unescape(x[1]);
		}
		this.initialized = true;
	},
	get: function(key) {
		return (this.__GET[key] != undefined) ? this.__GET[key] : false;
	},
	set: function(params) {
		//params {'key':'value', 'key2':'value2'}
		try {
			for (key in params) {
				if (key != '')
					this.__GET[key] = params[key];
			}
		} catch(e) {}
	},
	serialize: function() {
		params = [];
		for (key in this.__GET)
			if (key != '')
				if (this.__GET[key] != undefined)
					params.push(key + '=' + escape(this.__GET[key]))
		
		return params.join('&');
		
	},
	Cookie: {
		set: function(name,value,days,path,domain,secure) {
			if (!days) days = 360;
		    
			var date = new Date();
		    date.setTime(date.getTime() + (days*24*60*60*1000) );
		   	expires = date.toGMTString();
		  	
		   document.cookie = name + "=" + escape(value) +
		    ((expires) ? "; expires=" + expires : "") +
		    ((path) ? "; path=" + path : "") +
		    ((domain) ? "; domain=" + domain : "") +
		    ((secure) ? "; secure" : "");
		},

		get: function(name) {
		  var nameEQ = name + "=";
		  var ca = document.cookie.split(';');
		  for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
		  }
		  return null;
		}
	}
}
Req.init();

var Util = {
		
		clean: function(parobj) {
			var notWhiteSpaceNode = /\S/;
				
			for (i=0;i<parobj.childNodes.length;i++){
				if ((parobj.childNodes[i].nodeType == 3) 
				&& (!notWhiteSpaceNode.test(parobj.childNodes[i].nodeValue))) {
					parobj.removeChild(parobj.childNodes[i]);
						i--;
				}
			}
		},
		is_abs: function(tag) {
				//console.log(tag.css('position'));
				//jquery dependency
				return tag.css('position') == 'absolute';
		}
		
	}









function TextScroller() 
{
	
	// @private

	var _text = '';
	var intrvl;
	
	// @public
	this.content = '';
	this.height = undefined;
	this.speed = 1;
	this.delay = 10;
	this.top = 0;
	this.dir = '+';
	this.allowForceDirectionChange = true;
	this.pauseOnMouseOver = true;
	this.showScrollBars = false;
	this.isPlaying = false;
	
	
	// @private Methods
	this.__init = function() {
				
		removeWhiteSpaceNodes(this.content);
		
		_text = this.content.childNodes[1];
		if (this.height != undefined)
			_text.style.height = this.height + 'px';
		
		if (this.showScrollBars)
			_text.style.overflow = 'auto';
		else
			_text.style.overflow = 'hidden';
		
		if (this.allowForceDirectionChange)
			E.add(_text, 'click', this.__changeDir.bind(this));
		
		if (this.pauseOnMouseOver) {	
			E.add(_text, 'mouseover', this.__stopScroll.bind(this));
			E.add(_text, 'mouseout', this.__startScroll.bind(this));
		}
		
		this.__startScroll();

	}
	
	
	
	this.__startScroll = function(e) {
		if (this.isPlaying) return;
		this.isPlaying = true;
		this.intrvl = setInterval("_animate()",60);
		var _tsH = _text.scrollHeight;
		var _tsT = _text.scrollTop;
		var H = this.height;
		var delay = this.delay;
		var speed = this.speed;
		var dc = 0;
		var y = _tsT;
		var self = this;
		_animate = function() {	
			if (self.dir == '+') {
				//if (y >= (_tsH/1.5)-1) {
				if ((_tsH - y) <= H) {
					if (dc == delay) {
						self.dir = '-'; dc = 0;
					} else 
						dc += 1;
				} else {
					y+=speed;
				}
			} else {
				if (y <= -10) {
					if (dc == delay) { 
						self.dir = '+'; dc = 0;
					} else 
						dc += 1;
				} else {
					y-=speed;
				}
			}
		_text.scrollTop = y;
		}	
	
	}
	
	this.__changeDir = function(e) {
		this.dir = (this.dir == '-') ? '+' : '-';
	}
	
	this.__stopScroll = function(e) {
		clearInterval(this.intrvl);
		this.isPlaying = false;
	}
	
	this.startScroll = function(pnl) {
		this.__init(); //will start after initialising.
		//to call without init, use private method __startScroll
	}
	
	
	
}



function setTextScroller() {
	pnl = getById("fragsuccess");	
	
	if (pnl) {
		scroller = new TextScroller();
		scroller.speed = 1;
		scroller.delay = 20; //delay at begin and end
		scroller.height = 100; // height of the box. this can also be set using css
		scroller.content = pnl; //
		scroller.allowForceDirectionChange = true; //changes direction on click
		scroller.pauseOnMouseOver = true;
		scroller.startScroll();
		
	} else {
		return;
	}

}


PNG = {
	fixed: [],
	needFix: function (img) {
		var ie = isIE();
		if (!ie)
			return false;

		var arVersion = ie.split("MSIE")
		var version = parseFloat(arVersion[1])
	
		if ((version <= 5.5) || (!document.body.filters))
			return false;
		
		var imgName = img.src
		if (!imgName)
			return false;
		
		imgName = imgName.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) != "PNG")
			return false;
		
		return true;
	},
	isFixed: function(img) {
		for (f=0;f<this.fixed.length;f++) {
			if (this.fixed[f] == img)
				return true;
				
		}
		return false;
	},

	fixAll: function() {
		var imgs = d.getByTag('img');
		var imgl = imgs.length;
		
	   for(var i=0; i<imgl; i++) {
		  this.fix(imgs[i]);  
	   }
	
	},
	
	fix: function(img) {
		
		if (!this.needFix(img) || this.isFixed())
			return true;
		
		
		var src = img.src;		
		var imgName = src.toUpperCase()
		
		var imgID = (img.id) ? "id='" + img.id + "' " : ""
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML

		this.fixed.push(img);
	}
}

function fixPNG(img) {
	PNG.fix(img);
}

fixed_all_pngs = false;
function fixPNGs() {
	PNG.fixAll();	
}



function rand(end) {
	return Math.floor(Math.random()*end);
}


	
function ImageRotator(container, image_arr) {
	this.container = container;
	this.images = image_arr;
	return true;
}
ImageRotator.prototype.start = function() {
	var c = document.getElementById(this.container)
	if(!c) return;
	
	var r = rand(this.images.length)
	var last = Req.Cookie.get('last_img')
	while (r == last) {
		r = rand(this.images.length);
	}
	c.style.background = 'url('+this.images[r]+') no-repeat right';
	Req.Cookie.set('last_img', r);
	
}




__n = false;
function isIE(version) {
	if (!__n)
		__n = navigator.appVersion;

	if (__n.indexOf('MSIE') != -1)
		return __n;
	
	return false;
}

function newWin(loc, w, h) {
	if (!w) { w = 630;}
	if (!h) { h = 500;}
	window.open(loc,"images","height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes");
	return false;
	
}

var lBox = {
	Cache: {
		__cached__:{},
		get: function(id) { return this.__cached__[id] },
		put: function(id, content) { this.__cached__[id] = content;}
	},
	init: function(url, id) {
		this.id = id || '__lbox__';
		this.url = url;
		$('body').prepend('<div class="lbox" id="'+this.id+'"><div id="'+this.id+'content" class="lbox_content"></div></div>');
		var lb = $('#'+this.id);
		
		lb.css({ position:'fixed', top:-300, left:'50%',marginLeft:-250, background: '#333', zIndex: 9000, height: 300, width:500})
		if (!isIE()) {		
		lb.animate({top: 0, opacity: 1.0}, 300);
		}
		lb.append('<div class="lbox_footer" id="'+this.id+'footer"><a href="#" id="'+this.id+'close_btn" class="lbox_close_btn">Close</a></div>');
		$('#'+this.id+'close_btn').bind('click', this.exit.bind(this)).css({color:'#fff'});
		$('#'+this.id+'footer').css({padding:5});
		
		if (isIE()) { //ie hacks to fake positioned
			lb.css({position:'absolute'});
			
			sTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
				$('#'+this.id).css({top:sTop});
			
			window.onscroll = function() { 
				sTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
				$('#'+this.id).css({top:sTop});
			}.bind(this);
		}
		var _html = this.Cache.get(url);
		if (_html) this.set_content(_html)
		else $.get(url, {}, this.get_content.bind(this));
	},
	New: function(url) {
		this.init(url);
	},
	Confirm: function(url, cb) {
		this.init(url);
		this.onAction = cb;
		$('#'+this.id+'footer').append('<div class="buttons" style="float:right;"><button type="button" name="ok" id="'+this.id+'ok_button">Continue</button>\
							<button type="button" name="cancel" id="'+this.id+'cancel_button">Cancel</button></div>')
		
		$('#'+this.id+'ok_button').bind('click', this.user_action.bind(this));
		$('#'+this.id+'cancel_button').bind('click', this.user_action.bind(this));
	},
	exit: function(e) {
		$('#'+this.id).remove();
		if (isIE()) { window.onScroll = undefined};
	},
	user_action: function(e) {
		var btn = $(e.target)
		//console.log()
		action = (btn.attr('name') == 'ok' ? true : false)
		this.onAction(action);
	},
	get_content: function(html) {
		this.Cache.put(this.url, html)
		this.set_content(html);
	},
	set_content: function(html) {
		$('#'+this.id+'content').empty().append(html);
	}
	
}

var Jhllp = {
	init: function() {
		this.CForm.init();
	},
	CForm: {
		init: function() {
			//emails = $('a.emllink');
			form = $("#contactform.fragment form");
			form.bind('submit', this.show_disclaimer.bind(this));
			//console.log(form.attr('name'))
		},
		show_disclaimer: function(e) {
			e.preventDefault();
			this._form = e.target;
			
			lBox.Confirm('files/email_disclaimer.html', this.user_decide.bind(this));
		},
		user_decide: function(confirmed) {
			if (confirmed)
				this._form.submit();
			else
				this._form = undefined;
				
			lBox.exit();
		}
	}	
}

window.onload = function() {
	Jhllp.init();
}


















