// require jQuery 1.4.2 //

// ===== basic settings ===== //

(function() {
	jQuery.fn.initRollOverImages = function(config){
		// define class="rollover"
		var image_cache = new Object();
		jQuery("a.rollover img, img.rollover, input.rollover").each(function(i) {
			var imgsrc = this.src;
			var dot = this.src.lastIndexOf('.');
			var imgsrc_on = this.src.substr(0, dot) + '-on' + this.src.substr(dot, 4);
			image_cache[this.src] = new Image();
			image_cache[this.src].src = imgsrc_on;
			jQuery(this).hover(
				function() { this.src = imgsrc_on; },
				function() { this.src = imgsrc; }
			);
		});
	}

	jQuery.fn.initBrightOverImages = function(config){
		// define class="brightover"
		jQuery("a.brightover img, img.brightover").each(function(i) {
			jQuery(this).hover(
				function() {
					jQuery(this).stop();
					jQuery(this).css('opacity', '0.9');
					jQuery(this).animate({ opacity: 0.85 }, 300);
				},
				function() {
					jQuery(this).stop();
					//jQuery(this).css('opacity', '0.7');
					jQuery(this).animate({ opacity: 1.0 }, 300);
				}
			);
		});
	}

	jQuery.fn.initBannerRollOverImages = function(config){
		// define class="bannerrollover"
		jQuery("a.bannerrollover img, img.bannerrollover").each(function(i) {
			var frameWidth = this.width - 2 + "px";
			var frameHeight = this.height - 2 + "px";
			var frame = jQuery("<span />");
			jQuery(frame).css({
				'width': frameWidth,
				'height': frameHeight,
				'display': 'none',
				'position': 'absolute',
				'left': '0',
				'top': '0',
				'border': '1px solid #033861'
			});
			jQuery(this).parent("a").hover(
				function() {
					jQuery(frame).css({"display": "block"});
					jQuery(frame).appendTo(jQuery(this));
				},
				function() {
					jQuery(frame).css({"display": "none"});
					jQuery(this).children("span").remove();
				}
			);
			jQuery(this).css({  // for IE6,7
				"margin": "-3px",
				"padding": "3px"
			});
			jQuery(this).load(
				function() {
					jQuery(this).css({
						"margin": "0",
						"padding": "0"
					});
				}
			);
		});
	}

	jQuery.fn.initSmoothScroll = function(config){
		// define class="smoothscroll"
		var target = this;
		jQuery("a.smoothscroll").each(function(i) {
			jQuery(this).click(function () {
				jQuery(target).blur();
				jQuery('html,body').animate({ scrollTop: 0 }, 900, 'swing');
				return false;
			});
		});
	}

})(jQuery);

jQuery(document).ready(function() {
	jQuery(document).initRollOverImages();
	jQuery(document).initBrightOverImages();
	jQuery(document).initBannerRollOverImages();
	jQuery(document).initSmoothScroll();
});

