function clearsearch() {
    if (searchbox.value=="Search...")
    {
        searchbox.value = ""
    }
}

jQuery(function(){
	iepngfix();
	slide('gallery', 'link', 'timeline-holder', 'timeline', 750);
	slide('map-wrapper', 'map', 'map-holder', 'map', 220);
	popup();
});

function iepngfix() {
    if (document.all && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
    {
        document.styleSheets[0].addRule('.srch', 'behavior: url(iepngfix.htc)');
    }
}

function popup(){
	var _holder = jQuery(".popup-holder");
	_holder.each(function(){
		var _this =jQuery(this);
		var _link = jQuery("a.open", _this);
		var _popup = jQuery("div.popup", _this);
		var _close = jQuery("a.close", _popup);
		_link.click(function(){
			if (!_this.hasClass("active")) {
				_this.addClass("active");
			} else _this.removeClass("active");
			return false;
		});
		_close.click(function(){
			_this.removeClass("active");
			return false;
		});
	});	
}

function slide(holder_class, link_class, parent_class, mover_class, step){
	var _holder = jQuery("." + holder_class);
	_holder.each(function(){
		var _prev = jQuery("a." + link_class + "-prev", jQuery(this));
		var _next = jQuery("a." + link_class + "-next", jQuery(this));
		var _parent = jQuery("." + parent_class, jQuery(this));
		var _mover = jQuery("." + mover_class, _parent);
		var _step = step;
		var _m = 0;
		var _f =true;
		var _dur = 700;
		var _w = _mover.innerWidth(true);
		var _pw = _parent.innerWidth(true);
		
		_prev.click(function(){
			if (_f) {
				_f=false;
				_m = parseInt(_mover.css("marginLeft")) ;
				if (_m == 0) {
					_m = -_w+_pw-_step;
				} else if (_m == (-_w+_pw)+_step*(Math.floor(_w/_pw)) && _m != 0) {
					_m =0-_step;
				}
				_mover.animate({marginLeft: _m + _step}, {queue: false, duration: _dur, complete: function(){
						_f=true;
					}
				})
			}
			return false;
		});
	
		_next.click(function(){
			if (_f) {
				_f=false;
				_m = parseInt(_mover.css("marginLeft"));
				if (_m == -_w+_pw) {
					_m = 0+_step;
				} else if (_m == -_step*(Math.floor(_w/_pw)) && _m != -_w+_pw+_step) {
					_m =-_w+_pw+_step;
				}
				_mover.animate({marginLeft: _m-_step}, {queue: false, duration: _dur, complete: function(){
						_f=true;
					}
				})
			}
			return false;
		});
	});
}
