/* Standard Macromedia functions for rollovers */

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function swap_back() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swap() { //v3.0
  var i,j=0,x,a=swap.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* ====================================================================================== */
prevElement = null;
// toggles a set of divs from view/hide or expand/collpase mode
function jsShowHide(target) {
	var element = document.getElementById(target);
		
	if(element) {
		//jsHideAll();
		if(prevElement) {
			if(prevElement.style.display == 'block') {
				prevElement.style.display = 'none';
				if(element == prevElement) {
					return;
				}
			}
		}
		if (element.style.display == 'none' || element.style.display == '') {
			element.style.display = 'block';
		} else {
			element.style.display = 'none';
		}
		prevElement = element;
	}
}
function jsHideAll() {
	for(var i=0;i<30;++i) {
		var id = "group_" + i;
		var thisID = document.getElementById(id);
		if(thisID)
			thisID.style.display = 'none';
	}
}
/* ====================================================================================== */
/* jQuery document-is-ready function. Place all calls here */
jQuery(document).ready(function() {

//	$("a[rel^='prettyPhoto']").prettyPhoto();
	/*$("a[rel^='prettyPopin']").prettyPopin({
		width:600
	});*/
	
	//preloadImages('images/mb_brands_f2.png','images/mb_campaigns_f2.png');

	//$("a:has(img)").css("text-decoration","none");	
	$("#delegate_code").change(function() {
		var did = $(this).val();
		if(did) {
			$("#delegate_table").slideUp("slow");
			//$("#hfevent_did").attr("value",did);
		} else {
			$("#delegate_table").slideDown("slow");
			//$("#hfevent_did").attr("value","");
		}
		
		/*$.ajax({
			url: "get_delegate.php?id=" + delegate_id,
			async: false,
			success: function(results,status) {
				});
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert(textStatus);
			}
		})*/
	});
	
	$(".digest_category").css("display","none");
	$(".press_content").css("display","none");
	$(".pw_content").css("display","none");

	// Digest expose, now using jQuery
	$(".dst").click(function(e) {
		e.preventDefault();
		var slide_id = "sc_" + $(this).attr("id").substr(3);

		if($(".digest_category:visible").size() && $(".digest_category:visible").attr("id") != slide_id) {
			$(".digest_category:visible").hide("fast",function() {
				$("#"+slide_id).toggle("fast");//.scrollTo($(this));
			});
		} else {
			$("#"+slide_id).toggle("fast");//.scrollTo($(this));
		}
	});

	// Press expose, now using jQuery
	$(".pst").click(function(e) {
		e.preventDefault();
		var slide_id = "sc_" + $(this).attr("id").substr(3);

		if($(".press_content:visible").size() && $(".press_content:visible").attr("id") != slide_id) {
			$(".press_content:visible").hide("fast",function() {
				$("#"+slide_id).toggle("fast");//.scrollTo($(this));
			});
		} else {
			$("#"+slide_id).toggle("fast");//.scrollTo($(this));
		}
	});

	// Parents' Week expose, now using jQuery
	$(".pwst").click(function(e) {
		e.preventDefault();
		var slide_id = "sc_" + $(this).attr("id").substr(3);

		if($(".pw_content:visible").size() && $(".pw_content:visible").attr("id") != slide_id) {
			$(".pw_content:visible").hide("fast",function() {
				$("#"+slide_id).toggle("fast");//.scrollTo($(this));
			});
		} else {
			$("#"+slide_id).toggle("fast");//.scrollTo($(this));
		}
	});


	// TOOLTIP
	//Select all specified tags with rel set to tooltip
	//title="<strong>title</strong><br />content" rel="jtip"
	$('img[rel=jtip]').wTooltip({
	    style: {
	        border: "1px solid #2d6e8c",
	        background: "#e2f2f5",
	        color: "#001e3f",
	        fontWeight: "normal",
	        fontSize:"11px",
	        width:"200px",
	        padding:"4px"
	    }
	});
	
	if($('#hf_alert').size() != 0) {
		$('#hf_alert').slideDown("fast",function() {
			$('#hf_alert').fadeTo(3000,1).slideUp("fast");
		})		
	}


	
	// ============================================================
	// convert our taEmail class of links from a standard email link
	// to a non-clickable version. But on click, convert it back!
	$(".taEmail").each(function() {
		var newhref = this.href.replace(/%20at%20/,"@");
		//alert(newhref);
		$(this).attr("href",newhref);
	});
	$(".taEmail").click(function() {
		var newhref = this.href.replace(/%20at%20/,"@");
		//alert(newhref);
		$(this).attr("href",newhref).click();
	});

	// ============================================================
	$("#signup").submit(function(e){
     				
		// stop normal link click
		e.preventDefault();

		// send request
		if(this.signup_email.value != "Email address" && this.signup_email.value != "" && this.signup_name.value != "First name" && this.signup_name.value != "") {
			$("#signup_status").empty().addClass("ajax-loading");
			
			$.post("newsletterSignup.php", {signup_email:$("#signup_email").val(),signup_name:$("#signup_name").val()}, function(result) {
				// format and output result. fadeTo(3000,1) simulates delay(), which isn't in jQuery
				$("#signup_status").html(result).show("fast").fadeTo(3000,1).hide("fast");
				$("#signup_status").removeClass("ajax-loading");
			});
		}
	});


	// ============================================================
	// Font Resize methods. Provide 3 links with classes 
	// .resetFont, .increaseFont, decreaseFont. Size is saved in a 
	// Cookie (requires jqery.cookie.js as well as jquery.js)
	// Set size of body {} font
	// ------------------------------------------------------------
	var originalFontSize = '13px';//$('body').css('font-size');
	var originalFontSizeNum = parseFloat(originalFontSize);
	var cookie_name = 'textsize';
/*	
	if($.cookie(cookie_name))
		$('body').css('font-size', $.cookie(cookie_name));
	else
		$('body').css('font-size', originalFontSize);
*/
	// ------------------------------------------------------------
	// Reset Cookie
	$(".resetFont").click(function() {
		$('body').css('font-size', originalFontSize);
		$.cookie(cookie_name, null);
	});
	
	// ------------------------------------------------------------
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize);
		if(currentFontSizeNum < 20) {
			var newFontSize = currentFontSizeNum*1.2;
			$('body').css('font-size', newFontSize);
			$.cookie(cookie_name, newFontSize);
		}
		return false;
	});
	// ------------------------------------------------------------
	// Decrease Font Size
	$('.decreaseFont').click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum > 8) {
			var newFontSize = currentFontSizeNum*0.8;
			$('body').css('font-size', newFontSize);
			$.cookie(cookie_name, newFontSize);
		}
		return false;
	});

});


function twuSetTheme() {
	var originalFontSize = "13px";
	var originalFontSizeNum = parseFloat(originalFontSize);
	var cookie_name = 'textsize';
	
	if($.cookie(cookie_name))
		$('body').css('font-size', $.cookie(cookie_name) + "px");
	else
		$('body').css('font-size', originalFontSize);
}

// *************************************************************************
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */
	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };
// *************************************************************************
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/* Wayfarer Tooltip
 * Version 1.0.3
 * Author Abel Mohler
 * URI: http://www.wayfarerweb.com/wtooltip.php
 * Released with the MIT License: http://www.wayfarerweb.com/mit.php
 */
(function(a){a.fn.wTooltip=function(f,r){f=a.extend({content:null,ajax:null,follow:true,auto:true,fadeIn:0,fadeOut:0,appendTip:document.body,degrade:false,offsetY:10,offsetX:1,style:{},className:null,id:null,callBefore:function(t,p,o){},callAfter:function(t,p,o){},clickAction:function(p,o){a(p).hide()},delay:0,timeout:0,cloneable:false},f||{});if(!f.style&&typeof f.style!="object"){f.style={};f.style.zIndex="1000"}else{f.style=a.extend({border:"1px solid gray",background:"#edeef0",color:"#000",padding:"10px",zIndex:"1000",textAlign:"left"},f.style||{})}if(typeof r=="function"){f.callAfter=r||f.callAfter}f.style.display="none",f.style.position="absolute";var m,l,q,c,k={},b=true,e=false,n=false,s=document.createElement("div"),g=(typeof document.body.style.maxWidth=="undefined")?true:false,j=(typeof a.talk=="function"&&typeof a.listen=="function")?true:false;if(f.id){s.id=f.id}if(f.className){s.className=f.className}f.degrade=(f.degrade&&g)?true:false;for(var d in f.style){s.style[d]=f.style[d]}function i(o){if(o){if(f.degrade){a(s).html(f.content.replace(/<\/?[^>]+>/gi,""))}else{a(s).html(f.content)}}}if(f.ajax){a.get(f.ajax,function(o){if(o){f.content=o}i(f.content)})}function h(p){function t(u){if(m&&!f.content){u.title=m;m=null}}function o(){if(!e&&f.auto){clearInterval(c);if(f.fadeOut){a(s).fadeOut(f.fadeOut,function(){t(p)})}else{t(p);s.style.display="none"}}if(typeof f.callAfter=="function"){f.callAfter(s,p,f)}if(j){f=a.listen(f)}}if(f.timeout>0){q=setTimeout(function(){o()},f.timeout)}else{o()}}a(s).hover(function(){e=true},function(){e=false;h(k)});if(j){f.key=s;f.plugin="wTooltip";f.channel="wayfarer";a.talk(f)}i(f.content&&!f.ajax);a(s).appendTo(f.appendTip);return this.each(function(){this.onmouseover=function(t){var p=this;clearTimeout(q);if(this.title&&!f.degrade&&!f.content){m=this.title;this.title=""}if(f.content&&f.degrade){this.title=s.innerHTML}function o(){if(typeof f.callBefore=="function"){f.callBefore(s,p,f)}if(j){f=a.listen(f)}if(f.auto){var u;if(f.content){if(!f.degrade){u="block"}}else{if(m&&!f.degrade){a(s).html(m);u="block"}else{u="none"}}if(u=="block"&&f.fadeIn){a(s).fadeIn(f.fadeIn)}else{s.style.display=u}}}if(f.delay>0){l=setTimeout(function(){o()},f.delay)}else{o()}};this.onmousemove=function(y){var w=(y)?y:window.event,v=this;k=this;if(f.follow||b){var A=a(window).scrollTop(),B=a(window).scrollLeft(),x=w.clientY+A+f.offsetY,t=w.clientX+B+f.offsetX,z=a(f.appendTip).outerHeight(),p=a(f.appendTip).innerHeight(),o=a(window).width()+B-a(s).outerWidth(),u=a(window).height()+A-a(s).outerHeight();x=(z>p)?x-(z-p):x;n=(x>u||t>o)?true:false;if(t-B<=0&&f.offsetX<0){t=B}else{if(t>o){t=o}}if(x-A<=0&&f.offsetY<0){x=A}else{if(x>u){x=u}}s.style.top=x+"px";s.style.left=t+"px";b=false}};this.onmouseout=function(){clearTimeout(l);var o=this;b=true;if(!f.follow||n||(f.offsetX<0&&f.offsetY<0)){setTimeout(function(){c=setInterval(function(){h(o)},1)},1)}else{h(this)}};if(typeof f.clickAction=="function"){this.onclick=function(){f.clickAction(s,this)}}})}})(jQuery);