jQuery(document).ready(function() {

	/*
	hide_floater = jQuery.cookie('hide_floater');

	floater_counter = 1;
	floater_height = '';
	floater_width = '';
	floater_offset = '';
	floater_data = '';
	floater_data_entries = 1;
	floater_is_timing = 0;

	setTimeout("floaterStartFloating();", 3000);
	
	if ( hide_floater != '1' ) {
		
		jQuery("#floater").hide();
		jQuery.post("/floater-json-data.php", {}, function(result) {

			floater_data = eval("(" + result + ")");

			if ( floater_data.entry1_title == '' ) {
				return false;
			} else {
				
				if ( floater_data.entry2_title != '' ) {
					floater_data_entries = 2;
					floater_counter = Math.floor(Math.random()*2 + 1);
				}
				
				if ( floater_data.entry3_title != '' ) {
					floater_data_entries = 3;
					floater_counter = Math.floor(Math.random()*3 + 1);
				}
				
			}

			jQuery("#floater h4").html("<a href='" + floater_data.entry1_link + "'>" + floater_data.entry1_title + "</a>");
			jQuery("#floater #floater_text").html(floater_data.entry1_body);
			jQuery("#floater #floater_link").attr("href", floater_data.entry1_link);

			floater_height = jQuery("#floater").height();
			floater_width = jQuery("#floater").width();
			floater_offset = 0 - floater_width - 25;

			var w_height = jQuery(window).height();
			var vertical = jQuery(window).scrollTop() + w_height - floater_height - 40;
			jQuery("#floater").css("top", vertical);
			jQuery("#floater").css("left", floater_offset);
			
			jQuery(window).bind('scrollstart', function(){
				setTimeout("floaterStartFloating();", 3000);
			    });
	
			jQuery("#floater").show();
		});
		
	} else {
		
		jQuery("#floater").remove();
		
	}
	*/

	Cufon.replace('h1, h2, .right_col h4, #bigfooter .col h4, #bigfooter .col p, .copyright, .notice h4, .callout, #content #sidebar h3, .blurb2 h4, .sidenav .header, .productFeature h4');
	
	if (swfobject.hasFlashPlayerVersion("9.0.18")) {
		
		var flashvars = {};
		var attributes = {};
		attributes.wmode = "transparent";
		swfobject.embedSWF("/wp-content/themes/2020research/includes/piecemaker/piecemaker_custom4.swf", "cub3r", "920", "440", "9", "expressInstall.swf", flashvars, attributes);
		
	} else {
		
		scroller = jQuery(".scrollable").scrollable({
			loop: true,
			api: true,
			clickable: false,
			size: 1
		});

		setInterval("scroller.next();", 10000);
		
	}
	
	/*
	
	jQuery("#feeder li").hide();
	
	var left_li_count = jQuery("#feeder li").size();
	
	if ( left_li_count > 3 ) {
		
		left_li_step = 1;
		left_li_steps = Math.ceil(left_li_count / 3);
		
		var dot_counter = 1;
		while ( dot_counter <= left_li_steps ) {
			jQuery("#feed_dots").append("<img src='/wp-content/themes/2020research/media/dot_inactive.gif' class='feed_dot' /> ");
			dot_counter++;
		}
		
		var step_interval_id = setInterval("updateLiSteps();", 10000);
		updateLiSteps();
		
	} else {
		
		jQuery("#feeder li").fadeIn("slow");
		
	}
	
	jQuery(".feed_dot").click(function() {
		var this_eq = jQuery(".feed_dot").index(this);
		left_li_step = this_eq + 1;
		clearInterval(step_interval_id);
		updateLiSteps();
	});
	
	*/
	
	jQuery("a[rel='ss_series1']").colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
	jQuery("a[rel='ss_series2']").colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
	jQuery("a[rel='ss_series3']").colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
	jQuery("a[rel='ss_series4']").colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
	jQuery("a[rel='ss_series5']").colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
	
	jQuery(".videoCallout").click(function() {
		var rel = jQuery(this).attr("rel");

		jQuery.fn.colorbox({
			html: "<a href='" + rel + "' style='display:block;width:640px;height:480px' id='player'></a>",
			open: true,
			inline: false,
			transition: 'elastic',
			close: '',
			scrolling: false,
			title: 'Overview',
			onCleanup: function() {
			},
			onComplete: function() {
				flowplayer("player", "/wp-content/themes/2020research/includes/flowplayer/flowplayer-3.1.5.swf");
			}
		});

	});
	
	jQuery("#content #large .col:last").css("margin-right", "0px");
	
	/*
	try {
		jQuery('.scrollable .items').nivoSlider({
			effect: 'sliceDown',
			pauseTime: 10000
		});
	} catch(e) {
	}
	*/
	
	jQuery("#child_select").change(function() {
		var val = jQuery(this).val();
		if ( val == "Y" ) {
			jQuery("#kids").show();
		} else {
			jQuery("#kids").hide();
		}
	});
	
	jQuery(".panel_member").mouseover(function() {
		var alt = jQuery("img", this).attr("alt");
		jQuery("img", this).attr("src", alt);		
	});
	
	jQuery(".panel_member").mouseout(function() {
		var orig = jQuery("img", this).attr("orig");
		jQuery("img", this).attr("src", orig);		
	});
	
	jQuery(".productNav .items .item").mouseover(function() {
		jQuery(".productNav .items .item").removeClass("show");
		jQuery(this).addClass("show");
	});
	
	jQuery(".productNav .items .item").mouseout(function() {
		jQuery(".productNav .items .item").removeClass("show");
	});
	
	jQuery(".menu li").each(function() {
		if ( !jQuery(this).hasClass("active") ) {
			jQuery(this).addClass("inactive");
		}
	});
	jQuery(".menu li:first").removeClass("inactive");
	jQuery(".menu li:last").addClass("last");
	
	jQuery(".menu li").click(function() {
		var href = jQuery("a", this).attr("href");
		document.location = href;
	});

	jQuery("#search_input").focus(function() {
		var value = jQuery(this).val();
		if ( value == "Search..." ) {
			jQuery(this).val("");
		}
	});
	
	jQuery("#magnifier").click(function() {
		jQuery("#search_form").submit();
	});
	
	jQuery("#header #links2 ul li").click(function() {
		var href = jQuery("a", this).attr("href");
		window.location = href;
	});
	
	jQuery(".featureBox .links a").click(function() {
		jQuery(".featureBox .links li").removeClass("active");
		jQuery(this).closest("li").addClass("active");
		var rel = jQuery(this).attr("rel");
		jQuery(".featureBox .content").hide();
		jQuery(".featureBox #" + rel).fadeIn("slow");
		return false;
	});
	
	jQuery(".featureBox .links li").click(function() {
		jQuery("a", this).click();
	});
	
	jQuery(".column").livequery(function() {
		jQuery(".column").css("padding-right", "16px");
		jQuery(".column:last").css("padding-right", "0px");
	});

	/*
	Cufon.replace(jQuery("#header #links2"), {
		textShadow: '#3a3b3b -1px 1px'
	});
	Cufon.replace(jQuery("#header #links"));
	Cufon.replace(jQuery(".menu li"));
	Cufon.replace(jQuery(".newsletter"));
	*/
	
	jQuery(".feature_tabs").each(function() {
		jQuery(".ft_main:first", this).show();
	});
	
	jQuery(".ft_tabs").each(function() {
		jQuery(".ft_tab:last", this).addClass("last");
	});
	
	jQuery(".ft_tab a").click(function() {
		var rel = jQuery(this).attr("rel");
		var feature_tabs = jQuery(this).closest(".feature_tabs");
		jQuery(".ft_tab", feature_tabs).removeClass("active");
		jQuery(this).closest(".ft_tab").addClass("active");
		jQuery(".ft_main:visible", feature_tabs).hide();
		jQuery(".ft_main[rel='" + rel + "']", feature_tabs).show();	
		return false;
	});
	
	jQuery(".ft_tab").click(function() {
		var rel = jQuery("a", this).attr("rel");
		var feature_tabs = jQuery(this).closest(".feature_tabs");
		jQuery(".ft_tab", feature_tabs).removeClass("active");
		jQuery(this).closest(".ft_tab").addClass("active");
		jQuery(".ft_main:visible", feature_tabs).hide();
		jQuery(".ft_main[rel='" + rel + "']", feature_tabs).show();	
		return false;
	});

});

function facebox(content) {
	jQuery.facebox(content);	
}

function updateLiSteps() {
	
	var left_li_step_temp = left_li_step - 1;
	
	jQuery(".feed_dot").attr("src", "/wp-content/themes/2020research/media/dot_inactive.gif");
	jQuery(".feed_dot:eq(" + left_li_step_temp + ")").attr("src", "/wp-content/themes/2020research/media/dot_active.gif");
	
	var left_li_step_temp_start = left_li_step_temp * 3;
	
	var li_selector = "#feeder li:eq(" + ( left_li_step_temp_start + 0 ) + ")";
	li_selector += ", #feeder li:eq(" + ( left_li_step_temp_start + 1 ) + ")";
	li_selector += ", #feeder li:eq(" + ( left_li_step_temp_start + 2 ) + ")";
	
	if ( jQuery("#feeder li:visible").size() > 0 ) {
		
		jQuery("#feeder li:visible").fadeOut("slow", function() {
			jQuery(li_selector).fadeIn("slow");
		});
		
	} else {
		
		jQuery("#feeder li:visible").fadeOut("slow");
		jQuery(li_selector).fadeIn("slow");
		
	}
	
	left_li_step += 1;
	
	if ( left_li_step > left_li_steps ) {
		left_li_step = 1;
	}
	
}

function updateImage() {
	
	jQuery("#slide").attr("counter", image_counter + 1);
	
	var image_counter = jQuery("#slide").attr("counter") * 1;
	
	switch ( image_counter ) {
		
		case 1 :
		jQuery("#slide").attr("src", "/wp-content/themes/2020research/media/slide4.jpg");
		break;
		
		default :
		jQuery("#slide").attr("src", "/wp-content/themes/2020research/media/slide-all.jpg");
		jQuery("#slide").attr("counter", "0");
		break;
		
	}

}

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 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
 *
 */

// TODO JsDoc

/**
 * Create a cookie with the given key and value and other optional parameters.
 *
 * @example jQuery.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example jQuery.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example jQuery.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example jQuery.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 key The key 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 jQuery.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given key.
 *
 * @example jQuery.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name jQuery.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

/*
function hideFloater() {
	jQuery("#floater").hide();
	jQuery.cookie('hide_floater', '1', {
		expires: 1,
		path: '/',
		domain: 'www.2020research.com'
	});
}
*/

(function(){
 
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
 
    special.scrollstart = {
        setup: function() {
 
            var timer,
                handler =  function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
 
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid1, handler);
 
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
 
    special.scrollstop = {
        latency: 300,
        setup: function() {
 
            var timer,
                    handler = function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    }
 
                    timer = setTimeout( function(){
 
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
 
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid2, handler);
 
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
 
})();

/*
function floaterStartFloating() {

	if ( floater_is_timing == 0 ) {
		
		floater_is_timing = 1;
	
		jQuery("#floater").animate({
			left: floater_offset
		}, 400, function(){
			floaterStopFloating();
		});
	
	}
	
}

function floaterStopFloating() {
	
	if ( hide_floater != '1' ) {
		
		switch ( floater_data_entries ) {
			
			case 1 :
			jQuery("#floater h4").html("<a href='" + floater_data.entry1_link + "'>" + floater_data.entry1_title + "</a>");
			jQuery("#floater #floater_text").html(floater_data.entry1_body);
			jQuery("#floater #floater_link").attr("href", floater_data.entry1_link);
			break;
			
			case 2 :
			switch ( floater_counter ) {
				case 1 :
				jQuery("#floater h4").html("<a href='" + floater_data.entry1_link + "'>" + floater_data.entry1_title + "</a>");
				jQuery("#floater #floater_text").html(floater_data.entry1_body);
				jQuery("#floater #floater_link").attr("href", floater_data.entry1_link);
				break;
				case 2 :
				jQuery("#floater h4").html("<a href='" + floater_data.entry2_link + "'>" + floater_data.entry2_title + "</a>");
				jQuery("#floater #floater_text").html(floater_data.entry2_body);
				jQuery("#floater #floater_link").attr("href", floater_data.entry2_link);
				break;
			}
			floater_counter++;
			if ( floater_counter > 2 ) {
				floater_counter = 1;
			}
			break;
			
			case 3 :
			switch ( floater_counter ) {
				case 1 :
				jQuery("#floater h4").html("<a href='" + floater_data.entry1_link + "'>" + floater_data.entry1_title + "</a>");
				jQuery("#floater #floater_text").html(floater_data.entry1_body);
				jQuery("#floater #floater_link").attr("href", floater_data.entry1_link);
				break;
				case 2 :
				jQuery("#floater h4").html("<a href='" + floater_data.entry2_link + "'>" + floater_data.entry2_title + "</a>");
				jQuery("#floater #floater_text").html(floater_data.entry2_body);
				jQuery("#floater #floater_link").attr("href", floater_data.entry2_link);
				break;
				case 3 :
				jQuery("#floater h4").html("<a href='" + floater_data.entry3_link + "'>" + floater_data.entry3_title + "</a>");
				jQuery("#floater #floater_text").html(floater_data.entry3_body);
				jQuery("#floater #floater_link").attr("href", floater_data.entry3_link);
				break;				
			}
			floater_counter++;
			if ( floater_counter > 3 ) {
				floater_counter = 1;
			}
			break;
			
		}

		floater_height = jQuery("#floater").height();
		floater_width = jQuery("#floater").width();
		floater_offset = 0 - floater_width - 25;
		
		var w_height = jQuery(window).height();
		var vertical = jQuery(window).scrollTop() + w_height - floater_height - 40;
		jQuery("#floater").css("left", floater_offset);

		jQuery("#floater").animate({
			top: vertical
		}, 2000, function() {
		floater_is_timing = 0;
			jQuery("#floater").animate({
				left: 0
			}, 400, function(){
			});
		});
		
	}
	
}
*/

