// thumbnail popup

(function($) {
	$.fn.thumbPopup = function(options)
	{
		//Combine the passed in options with the default settings
		settings = jQuery.extend({
			popupId: "thumbPopup",
			popupCSS: {'border': '1px solid #000000', 'background': '#FFFFFF'},
			imgSmallFlag: "_t",
			imgLargeFlag: "_l",
			cursorTopOffset: 15,
			cursorLeftOffset: 15,
			loadingHtml: "<span style='padding: 5px;'>Loading</span>"
		}, options);
		
		//Create our popup element
		popup =
		$("<div />")
		.css(settings.popupCSS)
		.attr("id", settings.popupId)
		.css("position", "absolute")
		.appendTo("body").hide();
		
		//Attach hover events that manage the popup
		$(this)
		.hover(setPopup)
		.mousemove(updatePopupPosition)
		.mouseout(hidePopup);
		
		function setPopup(event)
		{
			var fullImgURL = $(this).attr("src").replace(settings.imgSmallFlag, settings.imgLargeFlag);
			$(this).data("hovered", true);
			
			//Load full image in popup
			$("<img />")
			.bind("load", {thumbImage: this}, function(event)
			{
				//Only display the larger image if the thumbnail is still being hovered
				if ($(event.data.thumbImage).data("hovered") == true) {
					$(popup).empty().append(this);
					updatePopupPosition(event);
					$(popup).show();
				}
				$(event.data.thumbImage).data("cached", true);
			})
			.attr("src", fullImgURL);
			
			//If no image has been loaded yet then place a loading message
			if ($(this).data("cached") != true) {
				$(popup).append($(settings.loadingHtml));
				$(popup).show();
			}
			
			updatePopupPosition(event);			
		}
		
		function updatePopupPosition(event)
		{
			var windowSize = getWindowSize();
			var popupSize = getPopupSize();
			if (windowSize.width + windowSize.scrollLeft < event.pageX + popupSize.width + settings.cursorLeftOffset){
				$(popup).css("left", event.pageX - popupSize.width - settings.cursorLeftOffset);
			} else {
				$(popup).css("left", event.pageX + settings.cursorLeftOffset);
			}
			if (windowSize.height + windowSize.scrollTop < event.pageY + popupSize.height + settings.cursorTopOffset){
				$(popup).css("top", event.pageY - popupSize.height - settings.cursorTopOffset);
			} else {
				$(popup).css("top", event.pageY + settings.cursorTopOffset);
			}
		}
		
		function hidePopup(event)
		{
			$(this).data("hovered", false);
			$(popup).empty().hide();
		}
		
		function getWindowSize() {
			return {
				scrollLeft: $(window).scrollLeft(),
				scrollTop: $(window).scrollTop(),
				width: $(window).width(),
				height: $(window).height()
			};
		}
		
		function getPopupSize() {
			return {
				width: $(popup).width(),
				height: $(popup).height()
			};
		}

		//Return original selection for chaining
		return this;
	};
})(jQuery);//$(document).ready

// hides the movie, shows when thumbnail clicked
$(function(){
	$('#homePage #movie_view').hide();
	$('#homePage #movie_thumbnail').click(function() {$('#homePage #movie_view').show('slow'); $('#homePage #movie_thumbnail').hide(); });
});

// for home page banner mouseovers
$(function(){
	$("#homePage #nav li#navAdvantage").mouseover (function() { $('#homePage #header').css('background-image', 'url(./images/home/banners/oa60.jpg)'); } );
	$("#homePage #nav li#navIllustrations").mouseover (function() { $('#header').css('background-image', 'url(./images/home/banners/illust60.jpg)'); } );
	$("#homePage #nav li#navCeus").mouseover (function() { $('#header').css('background-image', 'url(./images/home/banners/ceus60.jpg)'); } );
	$("#homePage #nav li#navAnimations").mouseover (function() { $('#header').css('background-image', 'url(./images/home/banners/anim60.jpg)'); } );
	$("#homePage #nav li#navForum").mouseover (function() { $('#header').css('background-image', 'url(./images/home/banners/forum60.jpg)'); } );
	$("#homePage #nav li#navBriefs").mouseover (function() { $('#header').css('background-image', 'url(./images/home/banners/briefs60.jpg)'); } );
	});
	
// for sub page banner mouseovers
$(function(){
	$(".subPage #nav li#navAdvantage").mouseover (function() { $('#header').css('background-image', 'url(../images/header/oa.jpg)'); } );
	$(".subPage #nav li#navIllustrations").mouseover (function() { $('#header').css('background-image', 'url(../images/header/illust.jpg)'); } );
	$(".subPage #nav li#navCeus").mouseover (function() { $('#header').css('background-image', 'url(../images/header/ceus.jpg)'); } );
	$(".subPage #nav li#navAnimations").mouseover (function() { $('#header').css('background-image', 'url(../images/header/animations.jpg)'); } );
	$(".subPage #nav li#navForum").mouseover (function() { $('#header').css('background-image', 'url(../images/header/forum.jpg)'); } );
	$(".subPage #nav li#navBriefs").mouseover (function() { $('#header').css('background-image', 'url(../images/header/briefs.jpg)'); } );
});

// for logo mouseover
$(function(){
	$(".subPage #header a#logoLink").mouseover (function() { $('#header').css('background-image', 'url(/images/header/home.jpg)'); } );
});

$(function(){
	$(".button").hover
		(
		function() { this.src = this.src.replace("_off","_on"); }, 
		function() { this.src = this.src.replace("_on","_off"); }
		);
	});

// thumb hover
$(function(){
//	$("div.thumbs img[src*='-thumb.jpg']").thumbPopup({
	$("td img[src*='-thumb.jpg']").thumbPopup({
		imgSmallFlag: "-thumb",
		imgLargeFlag: "-hover"
	});
});


// window popper

var newwindow;

function popAnimations(url)
{
	newwindow=window.open(url,'name','height=400,width=600,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
function popIllustration(url)
{
	newwindow=window.open(url,'name','height=700,width=740,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}

function popDermal(url)
{
	newwindow=window.open(url,'name','height=700,width=730,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
function popEeg(url)
{
	newwindow=window.open(url,'name','height=700,width=930,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
function popCranial(url)
{
	newwindow=window.open(url,'name','height=700,width=750,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
function popVideo(url)
{
	newwindow=window.open(url,'name','height=600,width=660,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}
// suckerfish

function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}

sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

sfActive = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmousedown=function() {
			this.className+=" sfactive";
		}
		sfEls[i].onmouseup=function() {
			this.className=this.className.replace(new RegExp(" sfactive\\b"), "");
		}
	}
}

sfTarget = function(sfEls) {
	var aEls = document.getElementsByTagName("A");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];
				aEls[j].onclick = function() {
					if (document.lastTarget) docu.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget";
					document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}
suckerfish(sfHover, "li");

// preload

$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}



/* 
 * No Spam (1.3)
 * by Mike Branski (www.leftrightdesigns.com)
 * mikebranski@gmail.com
 *
 * Copyright (c) 2008 Mike Branski (www.leftrightdesigns.com)
 * Licensed under GPL (www.leftrightdesigns.com/library/jquery/nospam/gpl.txt)
 *
 */

jQuery.fn.nospam = function(settings) {
	settings = jQuery.extend({
		replaceText: false, 	// optional, accepts true or false
		filterLevel: 'normal' 	// optional, accepts 'low' or 'normal'
	}, settings);
	
	return this.each(function(){
		e = null;
		if(settings.filterLevel == 'low') { // Can be a switch() if more levels added
			if($(this).is('a[rel]')) {
				e = $(this).attr('rel').replace('//', '@').replace(/\//g, '.');
			} else {
				e = $(this).text().replace('//', '@').replace(/\//g, '.');
			}
		} else { // 'normal'
			if($(this).is('a[rel]')) {
				e = $(this).attr('rel').split('').reverse().join('').replace('//', '@').replace(/\//g, '.');
			} else {
				e = $(this).text().split('').reverse().join('').replace('//', '@').replace(/\//g, '.');
			}
		}
		if(e) {
			if($(this).is('a[rel]')) {
				$(this).attr('href', 'mailto:' + e);
				if(settings.replaceText) {
					$(this).text(e);
				}
			} else {
				$(this).text(e);
			}
		}
	});
};

$(document).ready(function(){
  $('a.email').nospam({ filterLevel: 'low' });
 });



