﻿$(function(){
$("#footer").children("div.bottomteaser:first").css("margin-top","-171px").after("<div class='clear'></div>");
//$("#footer > div.bottomteaser").css("margin-top","-171px");
	//highlightWord($("body")[0],"Lorem");
	//$.bpalib(["striper", "expands", "popup", "external", "autoClearInput", "jqtabs"]);
//	$.tabberize();
//	$(".jqtab").tabberise("h3");
	//$.formreplacement();
  $.addicons(".mask");
//-->scroll to pagetop<--
//	$('.totop').click(function(){$('#top').ScrollTo(800);return false});
//-->jcarousel<--
//	$('.jcarousel-skin-tng').jcarousel({scroll: 6});
//-->accordion<--
//	$('.accordion').accordion({autoheight: false});
//-->Caption<--
/*	$('.captionImage3').imageCaption({
		toCaption: 'captionImage3',
		speedIn: 200,
		speedOut: 200,
		captionBoxOpacity: '0.5'
	});
	$("img.shadow").dropshadow();
	$("#test").roundcorners();
	$("select.replace").selectreplacement();
	$("input.liquid").inputdings();
*/
});


//-->dropshadow<--
$.fn.extend({
	dropshadow: function() {
		return this.each(function() {
			$(this).wrap('<div><div class="st"><div class="sr"><div class="sb"><div class="sl"></div></div></div></div></div>')
					.css({ float: "left", position: "absolute" })
					.before('<div class="stl"></div><div class="str"></div><div class="sbl"></div><div class="sbr"></div>');
			$(this).parent("div.sl").width($(this).width()).height($(this).height());
		});
	},
	roundcorners: function() {
		return this.each(function() {
			$(this).wrap('<div class="roundedbox"><div class="mid"><div></div></div></div>')
			$(this).parents("div.roundedbox").prepend('<div class="top"><div class="rig"></div><div class="lef"></div></div>');
			$(this).parents("div.roundedbox").append('<div class="bot"><div class="rig"></div><div class="lef"></div></div>');
		});
	},
	inputdings: function() {
		return this.each(function() {
			$(this).wrap('<div class="liquid"></div>')
		});
	},
	selectreplacement: function() {
		return this.each(function(i, n){
			$(n).hide().after('<div class="dropdown"><p><span></span></p><ul style="position:absolute; background:#0f6;"></ul></div>');
			$(n).next(".dropdown").children("p").children("span").text($(this).children("option:first").text());
		
			$.each( $(n).children("option"), function(j, o){
				$(n).next(".dropdown").children("ul").append('<li><span>' + $(o).text() + '</span></li>');
			});
			$(n).next(".dropdown").children("ul").hide().children("li:first").hide();
		
			$(n).next(".dropdown").hover(function(){
				$(this).css({cursor: "pointer"});
				$(this).bind("click", function(){
					if(!$(this).hasClass("iamopen")){
						$(".dropdown").children("ul").hide(); //clear all dropdowns
						$(this).toggleClass("iamopen").children("ul").animate({height: 'toggle', opacity: 'toggle'}, "fast");
						$(this).children("ul").children("li").bind("click", function(){
							$(this).parents(".dropdown").children("p").children("span").text($(this).text());
						});				
					} else {
						$(this).toggleClass("iamopen").children("ul").animate({height: 'toggle', opacity: 'toggle'}, "fast").children("li").unbind("click");
					}
				});
				$("html").unbind("click");
			},function(){
				$(this).unbind("click");
				if($(this).hasClass("iamopen")){
					var obj = this;
					$("html").bind("click", function(){
						$(obj).removeClass("iamopen").children("ul").animate({height: 'toggle', opacity: 'toggle'}, "fast");
						$("html").unbind("click");
					});				
				}	
			});
		});
	}
});
//-->Image Zoom<--
jQuery.zoomImg = function () {
	$.each( $("dl.zoomable"), function(i, n){
		$(n).css({cursor: 'pointer'}).children(":first").children("img:first").after('<img src="img/icons/search.gif" alt="zoom" class="zoomicon"/>');
		$(n).width($(n).children(":first").children("img:first").width() + 12);
	});
	$("dl.zoomable").click(function(){
		if($(this).hasClass("zoomed")){
			img = $("dt > img").attr("src").replace(new RegExp("-zoomed.jpg\\b"), ".jpg")
		} else {
			img = $("dt > img").attr("src").replace(new RegExp(".jpg\\b"), "-zoomed.jpg")
		}
		$(this).toggleClass("zoomed");
		$(this).children(":first").children("img:first").attr("src", img);
		if($(this).hasClass("zoomed")){
			$(this).width("auto");
		} else {
			$(this).width($(this).children(":first").children("img:first").width() + 12);
		}
	});
};
//-->checkbox/radio-replacement<--
jQuery.formreplacement = function () {
	$.each( $("label[@for]"), function(i, n){
		if($(n).next("input").hasClass("replace")){
			$(n).next("input").removeClass("replace").addClass("chbxhide");
			if ($(n).next("input").attr("type") == "checkbox") {
				$(n).addClass("chbx");
				$(n).click(function(){
					$(n).toggleClass("chkd");
				});
			} else {
				$(n).addClass("rd");
				$(n).click(function(){
					labelname = $(n).next().attr("name");
					$.each( $("input[@name="+labelname+"]"), function(j, o){
						if($(o).hasClass("chbxhide")){
							$(o).prev("label").removeClass("chkd");
						}
					});
					$(n).addClass("chkd");
				});
			}
			if ($(n).next("input").attr("checked")) {
						$(n).addClass("chkd");
			}
		}
	});
};
//-->jqtabs<--
		$.fn.extend({
			tabberise: function(elem) {
				return this.each(function(i, n) {
					$(n).prepend("<ul></ul>");
					var defaulttab = 1;
					$.each( $(n).children(elem), function(j, o){
						$(o).addClass("screenhide").parent("div.jqtab").children("ul").append('<li><a href="#tab'+i+'-'+j+'">' + $(o).html() + '</a></li>');
						$(o).next("div").attr("id","tab"+i+"-"+j);
						if($(o).next("div").hasClass("open")){
							defaulttab = j+1;
						}
					});
					$(n).tabs(defaulttab, { fxSlide: true, fxFade: true, fxSpeed: 'normal' }); // activate tab
				});
			}
		});

jQuery.tabberize = function () {
	$.each( $(".jqtab"), function(i, n){
		$(n).prepend("<ul></ul>");
		var defaulttab = 1;
		$.each( $(n).children("h3"), function(j, o){
			$(o).addClass("screenhide").parent("div.jqtab").children("ul").append('<li><a href="#tab'+i+'-'+j+'">' + $(o).html() + '</a></li>');
			$(o).next("div").attr("id","tab"+i+"-"+j);
			if($(o).next("div").hasClass("open")){
				defaulttab = j+1;
			}
		});
		$(n).tabs(defaulttab, { fxSlide: true, fxFade: true, fxSpeed: 'normal' }); // activate tab
	});
};

// addicons //
jQuery.addicons = function(options) {
	var elem = options.split(",");
	for(var i = 0; i<elem.length; i++){
		$(elem[i] +" a[@target='_blank']").addClass("blank");
		$(elem[i] +" a[@rel=external]").addClass("blank");
		$(elem[i] +" a[@href*=pdf]").addClass("pdf");
		$(elem[i] +" a[@href*=doc]").addClass("doc");
		$(elem[i] +" a[@href*=xls]").addClass("xls");
		$(elem[i] +" a[@href*=zip]").addClass("zip");
		$(elem[i] +" a[@href*=mp3]").addClass("mp3");
		$(elem[i] +" a[@href*=window.print()]").addClass("print");
		$(elem[i] +" a[@href*=#top]").addClass("totop");
		$(elem[i] +" a[@href*=mailto:]").addClass("mailto");
	}
};

// bpalib //
(function($j){
	$j.bpalib = function(enabled_modules){
		
		var modules = {
			
			striper: function(){
				$j(".striped").children(":odd").addClass("odd");
			},

			expands: function(){
				$j("h3.expand").css({cursor: "pointer"});
				$j("h3.expand").hover(
					function(){$j("h3.expand").addClass("hover");},
					function(){$j("h3.expand").removeClass("hover");
				});
				$j("h3.expand").next().addClass("screenhide");
				$j("h3.expand").next(".open").show().prev().toggleClass("selected");
				$j("h3.expand").click(function(){
					$(this).toggleClass("selected").next().animate({height: 'toggle', opacity: 'toggle'}, "fast");
				});
			},

			popup: function(){
				$j("a[@rel^=popup]").click(function(){
					var dims = this.getAttribute('rel').match(/.*\[([0-9]+)-([0-9]+)\].*/);
					window.open(this.getAttribute('href'),'Info','width=' + dims[1] + ',height=' + dims[2] + ',resizable,scrollbars');
					return false;
				});
			},
			external: function(){
				$j("a[@rel=external]").click(function(){
					window.open(this.getAttribute('href'));
					return false;
				});
			},
			autoClearInput: function(){
				$j("input.autoclear:text, input.autoclear:password").focus(function(){
					if (this._defaultValue == this.value){
						this.value="";
					}
				})
				.each(function(){
					this._defaultValue = this.getAttribute("value");
				});
			},
			
			autoFocusInput: function(){
				var focusElmts = $j("input.autofocus");
				if (focusElmts.length != 0){
					 focusElmts.get(0).focus();
				}
			}
		};
		
		if (enabled_modules){
			$j.each(enabled_modules,function(i,n){
				if(modules[n]){
					modules[n](i);
				}
			});
		}
		else {
			$j.each(modules,function(i,n){n();});
		}
		
	};
})(jQuery);

// scroll //
jQuery.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = jQuery.intval(jQuery.css(e,'width'));
	var h = jQuery.intval(jQuery.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?jQuery.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?jQuery.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};
jQuery.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};
jQuery.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};
jQuery.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};
jQuery.fn.ScrollTo = function(s) {
	o = jQuery.speed(s);
	return this.each(function(){
		new jQuery.fx.ScrollTo(this, o);
	});
};
jQuery.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = jQuery.getPos(e);
	z.s = jQuery.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

