$(document).ready(function(){

// ------------------------------------------------	
	// png fix
	// fix ie6
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		// png fix
		$('img[src$=.png]').each(function() {
			if (!this.complete) {
				this.onload = function() { fixPng(this) };
			} else {
				fixPng(this);
			}
		});
		// cache bg images
		try {
			document.execCommand("BackgroundImageCache", false, true);
		  } catch(err) {}
	}


// ------------------------------------------------	
	// form controls
	$("#login input").each(function(){
		$(this).val($(this).attr("title"));
	});
	$("#login input").focus(function(){
		if ($(this).val() == $(this).attr("title")) { 
			$(this).val(""); 
		}
	}).blur(function(){
		if ($(this).val() == "") { 
			$(this).val($(this).attr("title"));
		}
	});
	


// ------------------------------------------------
	$(".toggler").click(function(){
		obj = "#" + $(this).attr("rel");
		$(obj).slideToggle();
		
		// catch equal employment on Contact Us
		switch (obj) {
			case '#equal_employment':
				$('.layer_1_cap_bottom').toggleClass('back_brown_2');
				break;
		}
		
		// catch Read/Hide Bio on About/Team page
		if ($(this).text() == 'Read Bio')
		{
			$(this).text('Hide Bio');
		}
		else if ($(this).text() == 'Hide Bio')
		{
			$(this).text('Read Bio');
		}
		return false;
	});
	
	$(".report_toggler").click(function(){
		$(this).parent().find(".report_hidden").toggle();
		
		// catch Show/Hide older reports on Secure Client fund page
		if ($(this).text() == 'Show older reports')
		{
			$(this).text('Hide older reports');
		}
		else if ($(this).text() == 'Hide older reports')
		{
			$(this).text('Show older reports');
		}
		return false;
	});
	
	
	
// ------------------------------------------------
	// initiate sidebar image corner rounding
	//$(".column_1 .graphic").corner().find("img:first").css('border-bottom','1px solid #e9e8de');
	$(".column_1 .graphic").css('position','relative').append('<div class="frame_large"></div>');
	$(".column_1 .news_graphic").css('position','relative').append('<div class="news_frame_top"></div><div class="news_frame_bottom"></div>');
	$(".fund_graphic").css('position','relative').append('<div class="frame_large"></div>');
	$(".strategy_item .photo").css('position','relative').append('<div class="frame_small"></div>');
	
	// make frames clickable
	$(".strategy_item .photo > a").each(function(){
		var url = $(this).attr('href');
		$(this).parents('.photo').css('cursor','pointer').click(function(){
			window.location = url;
		});
	});
	
	
	
// ------------------------------------------------	
	$('#news_ticker').innerfade({ 
		animationtype: 'slide', 
		speed: 'slow', 
		timeout: '5000', 
		type: 'sequence', 
		containerheight: '21px'
	}); 
	
	
	
// ------------------------------------------------
	// fix last subnav_item to prevent odd wrap
	$(".subnav_item:last").addClass('subnav_item_last');
	
	
	
// ------------------------------------------------
	// initiate home page flash feature
	if ($("#hero").length > 0)
	{
		var flashvars = { };
		var params = { menu: "false", scale: "scale", wmode: "opaque", allowfullscreen: "false" };
		var attributes = { id: "hero" };
		swfobject.embedSWF("/assets/swf/hero.swf", "hero", "980", "253", "9.0.45", "/assets/swf/expressinstall.swf", flashvars, params, attributes);
	}
	
	
// ------------------------------------------------
	// cufon substitution for AUM
	Cufon.replace('#caum div');
	
		
// ------------------------------------------------
	/*
		SCROLL FEATURE FOR FUND DETAILS
	*/
	if ($(".fund_module").length > 0 && ! $(".fund_module").hasClass('none'))
	{
		
		$('.fund_module').each(function(){
		
			var obj = "#" + this.id;
			
			var $container = $(obj + ' .fund_detail .fund_sections');
			var $panels = $(obj + ' .fund_detail .fund_sections > div');
			var $scroll = $(obj + ' .fund_detail');
			var $navigation = $(obj + '.fund_nav a');
			
			// handle nav selection
			function selectNav() {
				$(this).parents('.fund_nav').find('a').removeClass('current');
				$(this).addClass('current');
			}
			$(obj + ' .fund_nav a').click(selectNav);
			
			// go find the navigation link that has this target and select the nav
			function trigger(data) {
				var el = $(obj + ' .fund_nav a[href$="' + data.id + '"]:first');
				selectNav.call(el);
			}
			$(obj + ' .fund_nav a:first').click();
			
			var scrollOptions = {
				target: $scroll, // the element that has the overflow
				items: $panels, // can be a selector which will be relative to the target			
				navigation: $navigation,
				axis: 'x', // allow the scroll effect to run both directions			
				onAfter: trigger, // our final callback			
				duration: 500, // duration of the sliding effect
				easing: 'swing',
				force: true
			};
			
			// apply serialScroll to the slider - we chose this plugin because it 
			// supports// the indexed next and previous scroll along with hooking 
			// in to our navigation.
			$(obj + ' .fund_detail').serialScroll(scrollOptions);
			
			// now apply localScroll to hook any other arbitrary links to trigger 
			// the effect
			$(obj + ' .fund_nav').localScroll(scrollOptions);
		});
	}	
	
	/*
		END - SCROLL FEATURE FOR FUND DETAILS
	*/
	
	
	
// ------------------------------------------------
	/*
		SCROLL FEATURE FOR STRATEGY DETAILS
	*/
	if ($("#strategy_wrap").length > 0)
	{
		var $scroll = $('#strategy_wrap').css('overflow', 'hidden');
		var $panels = $('#strategy_wrap #strategy_listing > div.strategy_row');
		var $container = $('#strategy_wrap #strategy_listing');
		// calculate a new width for the container (so it holds all panels)
		$container.css('width', $panels[0].offsetWidth * $panels.length);
		
		// handle nav selection
		function selectNav() {
			$("#strategy_nav a.indicator").removeClass('current')
			$(this).addClass('current');
		}
		$('#strategy_nav').find('a.indicator').click(selectNav);
		
		// go find the navigation link that has this target and select the nav
		function trigger(data) {
			var el = $('#strategy_nav').find('a[href$="' + data.id + '"]').get(0);
			selectNav.call(el);
		}
		
		if (window.location.hash) {
			trigger({ id : window.location.hash.substr(1) });
		} else {
			$('#strategy_nav a.indicator:first').click();
		}
		
		// offset is used to move to *exactly* the right place, since I'm using
		// padding on my example, I need to subtract the amount of padding to
		// the offset.	Try removing this to get a good idea of the effect
		var offset = parseInt((true ? 
			$container.css('paddingTop') : 
			$container.css('paddingLeft')) 
			|| 0) * -1;
		
		
		// get current position left by php script and round up to next odd number for calculation in scrollOptions
		var dnum = $("#strategy_item").text();
		var inum = (Math.round(dnum));
		if (inum == dnum)
		{
			inum = inum + 1;
		}
		inum = Math.ceil(inum / 2) - 1;
		
		var scrollOptions = {
			target: $scroll, // the element that has the overflow 
			items: $panels,	// can be a selector which will be relative to the target
			navigation: '#strategy_nav a.indicator',					
			axis: 'xy', // allow the scroll effect to run both directions
			onAfter: trigger, // our final callback
			offset: offset,
			duration: 500, // duration of the sliding effect
			easing: 'swing',
			force: true,
			start: inum,
			cycle: false //don't pull back once you reach the end
		};
		
		// apply serialScroll to the slider - we chose this plugin because it 
		// supports// the indexed next and previous scroll along with hooking 
		// in to our navigation.
		$scroll.serialScroll(scrollOptions);
		
		// now apply localScroll to hook any other arbitrary links to trigger 
		// the effect
		$.localScroll(scrollOptions);
		
		// finally, if the URL has a hash, move the slider in to position, 
		// setting the duration to 1 because I don't want it to scroll in the
		// very first page load.	We don't always need this, but it ensures
		// the positioning is absolutely spot on when the pages loads.
		scrollOptions.duration = 1;
		$.localScroll.hash(scrollOptions);
		
		
		$("#strategy_nav div.prev").click(function(){
			$('#strategy_listing').trigger('prev');
		}).hover(function(){
			$(this).addClass("over");
		},function(){
			$(this).removeClass("over");
		});
		
		$("#strategy_nav div.next").click(function(){
			$('#strategy_listing').trigger('next');
		}).hover(function(){
			$(this).addClass("over");
		}, function(){
			$(this).removeClass("over");
		});		
	}	
	
	/*
		END - SCROLL FEATURE FOR STRATEGY DETAILS
	*/
	
	
	
// ------------------------------------------------
	// initiate google map on Contact Us page
	if ($("#map").length > 0)
	{
		onLoad();
	}
	
	
// ------------------------------------------------
	// Expander
	$(".expander").click(function(){
		var obj = "#" + $(this).attr("rel");
		$(this).toggleClass('expanded');
		$(obj).slideToggle();
		return false;
	});
	
	
// ------------------------------------------------
	// AJAX calls for fund modules
	$(".get_content").live("click", function(){
		var values = $(this).attr("rel").split("-");
		var type = values[0];
		var page = values[1];
		var id = $(this).parents(".fund_module").attr("id").split("_");
		var id = id[1];
		
		get_content(type, id, page, $(this));
		return false;
	});
	
	function get_content(url, id, page, obj)
	{
		var content = $(obj).parent().parent().parent();
		$.ajax({
			type: "POST",
			url: "/includes/secure_"+url+".php",
			data: "id=" + id + "&page=" + page,
			success: function(msg){
				$(content).slideUp().fadeOut('normal', function(){ 
					$(this).html(msg).fadeIn('normal', function(){
						$(this).slideDown(); 
					}); 
				});
			}
		});
		return false;
	}
	

// ------------------------------------------------
	// AJAX calls for editing client/consultant info
	$(".edit_info_link").live("click", function(){
		var $info = $(this).attr("rel").split('-');
		var $type = $info[0];
		var $user = $info[1];
		
		switch ($type)
		{
			case 'client':
				$.ajax({
					type: "GET",
					url: "/includes/secure_edit_client.php",
					data: "user="+$user,
					success: function(msg){
						$("#secure_info_col .client_info").html(msg);
						init_edit_form();
					}
				});
				break;
			case 'consultant':
				$.ajax({
					type: "GET",
					url: "/includes/secure_edit_consultant.php",
					data: "user="+$user,
					success: function(msg){
						$("#secure_info_col .client_info").html(msg);
						init_edit_form();
					}
				});
			break;
		}
		
		return false;
	});
	
	$("#edit_info_form button").live("click", function(){
		var $type = $(this).parent("form").attr("name");
		
		$("#edit_info_form input").each(function(){
			if ($(this).val() == $(this).attr("title"))
			{
				$(this).val("");
			}
		});
		
		$.ajax({
			type: "POST",
			url: "/includes/secure_edit_"+$type+".php",
			data: $("#edit_info_form").serialize(),
			success: function(msg){
				$("#secure_info_col .client_info").html(msg);
				if ($("#secure_info_col .client_info form").length == 0)
				{
					if ($type == "consultant")
					{
						var $new_name = $("#secure_info_col .client_info .consultant_name").text();
					}
					else
					{
						var $new_name = $("#secure_info_col .client_info .name").text();
					}
					$("a.logged_in_name").text($new_name);
				}
				else
				{
					init_edit_form();
				}
			}
		});
		
		return false;
	})

});





function init_edit_form()
{
	$("#edit_info_form input").each(function(){
		if ($(this).val() == "")
		{
			$(this).val($(this).attr("title"));
			$(this).css("color", "#777");
		}
	});
	$("#edit_info_form input").focus(function(){
		if ($(this).val() == $(this).attr("title"))
		{ 
			$(this).val("");
		}
		else
		{
			$(this).css("color", "#000");
		}
	}).blur(function(){
		if ($(this).val() == "") { 
			$(this).val($(this).attr("title"));
			$(this).css("color", "#777");
		}
		else
		{
			$(this).css("color", "#000");
		}
	});
}




/*!
 * jQuery corner plugin: simple corner rounding
 * Examples and documentation at: http://jquery.malsup.com/corner/
 * version 1.99 (28-JUL-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

/**
 *  corner() takes a single string argument:  $('#myDiv').corner("effect corners width")
 *
 *  effect:  name of the effect to apply, such as round, bevel, notch, bite, etc (default is round). 
 *  corners: one or more of: top, bottom, tr, tl, br, or bl. 
 *           by default, all four corners are adorned. 
 *  width:   width of the effect; in the case of rounded corners this is the radius. 
 *           specify this value using the px suffix such as 10px (and yes, it must be pixels).
 *
 * @name corner
 * @type jQuery
 * @param String options Options which control the corner style
 * @cat Plugins/Corner
 * @return jQuery
 * @author Dave Methvin (http://methvin.com/jquery/jq-corner.html)
 * @author Mike Alsup   (http://jquery.malsup.com/corner/)
 */
;(function($) { 

var expr = (function() {
	if (! $.browser.msie) return false;
    var div = document.createElement('div');
    try { div.style.setExpression('width','0+0'); }
    catch(e) { return false; }
    return true;
})();
    
function sz(el, p) { 
    return parseInt($.css(el,p))||0; 
};
function hex2(s) {
    var s = parseInt(s).toString(16);
    return ( s.length < 2 ) ? '0'+s : s;
};
function gpc(node) {
    for ( ; node && node.nodeName.toLowerCase() != 'html'; node = node.parentNode ) {
        var v = $.css(node,'backgroundColor');
        if (v == 'rgba(0, 0, 0, 0)')
            continue; // webkit
        if (v.indexOf('rgb') >= 0) { 
            var rgb = v.match(/\d+/g); 
            return '#'+ hex2(rgb[0]) + hex2(rgb[1]) + hex2(rgb[2]);
        }
        if ( v && v != 'transparent' )
            return v;
    }
    return '#ffffff';
};

function getWidth(fx, i, width) {
    switch(fx) {
    case 'round':  return Math.round(width*(1-Math.cos(Math.asin(i/width))));
    case 'cool':   return Math.round(width*(1+Math.cos(Math.asin(i/width))));
    case 'sharp':  return Math.round(width*(1-Math.cos(Math.acos(i/width))));
    case 'bite':   return Math.round(width*(Math.cos(Math.asin((width-i-1)/width))));
    case 'slide':  return Math.round(width*(Math.atan2(i,width/i)));
    case 'jut':    return Math.round(width*(Math.atan2(width,(width-i-1))));
    case 'curl':   return Math.round(width*(Math.atan(i)));
    case 'tear':   return Math.round(width*(Math.cos(i)));
    case 'wicked': return Math.round(width*(Math.tan(i)));
    case 'long':   return Math.round(width*(Math.sqrt(i)));
    case 'sculpt': return Math.round(width*(Math.log((width-i-1),width)));
    case 'dog':    return (i&1) ? (i+1) : width;
    case 'dog2':   return (i&2) ? (i+1) : width;
    case 'dog3':   return (i&3) ? (i+1) : width;
    case 'fray':   return (i%2)*width;
    case 'notch':  return width; 
    case 'bevel':  return i+1;
    }
};

$.fn.corner = function(o) {
    // in 1.3+ we can fix mistakes with the ready state
	if (this.length == 0) {
        if (!$.isReady && this.selector) {
            var s = this.selector, c = this.context;
            $(function() {
                $(s,c).corner(o);
            });
        }
        return this;
	}

    o = (o||"").toLowerCase();
    var keep = /keep/.test(o);                       // keep borders?
    var cc = ((o.match(/cc:(#[0-9a-f]+)/)||[])[1]);  // corner color
    var sc = ((o.match(/sc:(#[0-9a-f]+)/)||[])[1]);  // strip color
    var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10; // corner width
    var re = /round|bevel|notch|bite|cool|sharp|slide|jut|curl|tear|fray|wicked|sculpt|long|dog3|dog2|dog/;
    var fx = ((o.match(re)||['round'])[0]);
    var edges = { T:0, B:1 };
    var opts = {
        TL:  /top|tl/.test(o),       TR:  /top|tr/.test(o),
        BL:  /bottom|bl/.test(o),    BR:  /bottom|br/.test(o)
    };
    if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
        opts = { TL:1, TR:1, BL:1, BR:1 };
    var strip = document.createElement('div');
    strip.style.overflow = 'hidden';
    strip.style.height = '1px';
    strip.style.backgroundColor = sc || 'transparent';
    strip.style.borderStyle = 'solid';
    return this.each(function(index){
        var pad = {
            T: parseInt($.css(this,'paddingTop'))||0,     R: parseInt($.css(this,'paddingRight'))||0,
            B: parseInt($.css(this,'paddingBottom'))||0,  L: parseInt($.css(this,'paddingLeft'))||0
        };

        if (typeof this.style.zoom != undefined) this.style.zoom = 1; // force 'hasLayout' in IE
        if (!keep) this.style.border = 'none';
        strip.style.borderColor = cc || gpc(this.parentNode);
        var cssHeight = $.curCSS(this, 'height');

        for (var j in edges) {
            var bot = edges[j];
            // only add stips if needed
            if ((bot && (opts.BL || opts.BR)) || (!bot && (opts.TL || opts.TR))) {
                strip.style.borderStyle = 'none '+(opts[j+'R']?'solid':'none')+' none '+(opts[j+'L']?'solid':'none');
                var d = document.createElement('div');
                $(d).addClass('jquery-corner');
                var ds = d.style;

                bot ? this.appendChild(d) : this.insertBefore(d, this.firstChild);

                if (bot && cssHeight != 'auto') {
                    if ($.css(this,'position') == 'static')
                        this.style.position = 'relative';
                    ds.position = 'absolute';
                    ds.bottom = ds.left = ds.padding = ds.margin = '0';
                    if (expr)
                        ds.setExpression('width', 'this.parentNode.offsetWidth');
                    else
                        ds.width = '100%';
                }
                else if (!bot && $.browser.msie) {
                    if ($.css(this,'position') == 'static')
                        this.style.position = 'relative';
                    ds.position = 'absolute';
                    ds.top = ds.left = ds.right = ds.padding = ds.margin = '0';
                    
                    // fix ie6 problem when blocked element has a border width
                    if (expr) {
                        var bw = sz(this,'borderLeftWidth') + sz(this,'borderRightWidth');
                        ds.setExpression('width', 'this.parentNode.offsetWidth - '+bw+'+ "px"');
                    }
                    else
                        ds.width = '100%';
                }
                else {
                	ds.position = 'relative';
                    ds.margin = !bot ? '-'+pad.T+'px -'+pad.R+'px '+(pad.T-width)+'px -'+pad.L+'px' : 
                                        (pad.B-width)+'px -'+pad.R+'px -'+pad.B+'px -'+pad.L+'px';                
                }

                for (var i=0; i < width; i++) {
                    var w = Math.max(0,getWidth(fx,i, width));
                    var e = strip.cloneNode(false);
                    e.style.borderWidth = '0 '+(opts[j+'R']?w:0)+'px 0 '+(opts[j+'L']?w:0)+'px';
                    bot ? d.appendChild(e) : d.insertBefore(e, d.firstChild);
                }
            }
        }
    });
};

$.fn.uncorner = function() { 
	$('div.jquery-corner', this).remove();
	return this;
};
    
})(jQuery);	





/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);





/**
 * jQuery.LocalScroll - Animated scrolling navigation, using anchors.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/11/2009
 * @author Ariel Flesler
 * @version 1.2.7
 **/
;(function($){var l=location.href.replace(/#.*/,'');var g=$.localScroll=function(a){$('body').localScroll(a)};g.defaults={duration:1e3,axis:'y',event:'click',stop:true,target:window,reset:true};g.hash=function(a){if(location.hash){a=$.extend({},g.defaults,a);a.hash=false;if(a.reset){var e=a.duration;delete a.duration;$(a.target).scrollTo(0,a);a.duration=e}i(0,location,a)}};$.fn.localScroll=function(b){b=$.extend({},g.defaults,b);return b.lazy?this.bind(b.event,function(a){var e=$([a.target,a.target.parentNode]).filter(d)[0];if(e)i(a,e,b)}):this.find('a,area').filter(d).bind(b.event,function(a){i(a,this,b)}).end().end();function d(){return!!this.href&&!!this.hash&&this.href.replace(this.hash,'')==l&&(!b.filter||$(this).is(b.filter))}};function i(a,e,b){var d=e.hash.slice(1),f=document.getElementById(d)||document.getElementsByName(d)[0];if(!f)return;if(a)a.preventDefault();var h=$(b.target);if(b.lock&&h.is(':animated')||b.onBefore&&b.onBefore.call(b,a,f,h)===false)return;if(b.stop)h.stop(true);if(b.hash){var j=f.id==d?'id':'name',k=$('<a> </a>').attr(j,d).css({position:'absolute',top:$(window).scrollTop(),left:$(window).scrollLeft()});f[j]='';$('body').prepend(k);location=e.hash;k.remove();f[j]=d}h.scrollTo(f,b).trigger('notify.serialScroll',[f])}})(jQuery);





/*
 * jQuery.SerialScroll - Animated scrolling of series
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 06/14/2009
 * @author Ariel Flesler
 * @version 1.2.2
 * http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 */
;(function(a){var b=a.serialScroll=function(c){return a(window).serialScroll(c)};b.defaults={duration:1e3,axis:"x",event:"click",start:0,step:1,lock:!0,cycle:!0,constant:!0};a.fn.serialScroll=function(c){return this.each(function(){var t=a.extend({},b.defaults,c),s=t.event,i=t.step,r=t.lazy,e=t.target?this:document,u=a(t.target||this,e),p=u[0],m=t.items,h=t.start,g=t.interval,k=t.navigation,l;if(!r){m=d()}if(t.force){f({},h)}a(t.prev||[],e).bind(s,-i,q);a(t.next||[],e).bind(s,i,q);if(!p.ssbound){u.bind("prev.serialScroll",-i,q).bind("next.serialScroll",i,q).bind("goto.serialScroll",f)}if(g){u.bind("start.serialScroll",function(v){if(!g){o();g=!0;n()}}).bind("stop.serialScroll",function(){o();g=!1})}u.bind("notify.serialScroll",function(x,w){var v=j(w);if(v>-1){h=v}});p.ssbound=!0;if(t.jump){(r?u:d()).bind(s,function(v){f(v,j(v.target))})}if(k){k=a(k,e).bind(s,function(v){v.data=Math.round(d().length/k.length)*k.index(this);f(v,this)})}function q(v){v.data+=h;f(v,this)}function f(B,z){if(!isNaN(z)){B.data=z;z=p}var C=B.data,v,D=B.type,A=t.exclude?d().slice(0,-t.exclude):d(),y=A.length,w=A[C],x=t.duration;if(D){B.preventDefault()}if(g){o();l=setTimeout(n,t.interval)}if(!w){v=C<0?0:y-1;if(h!=v){C=v}else{if(!t.cycle){return}else{C=y-v-1}}w=A[C]}if(!w||t.lock&&u.is(":animated")||D&&t.onBefore&&t.onBefore(B,w,u,d(),C)===!1){return}if(t.stop){u.queue("fx",[]).stop()}if(t.constant){x=Math.abs(x/i*(h-C))}u.scrollTo(w,x,t).trigger("notify.serialScroll",[C])}function n(){u.trigger("next.serialScroll")}function o(){clearTimeout(l)}function d(){return a(m,p)}function j(w){if(!isNaN(w)){return w}var x=d(),v;while((v=x.index(w))==-1&&w!=p){w=w.parentNode}return v}})}})(jQuery);






/* =========================================================

// jquery.innerfade.js

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

 *
 *  <ul id="news"> 
 *      <li>content 1</li>
 *      <li>content 2</li>
 *      <li>content 3</li>
 *  </ul>
 *  
 *  $('#news').innerfade({ 
 *	  animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'), 
 *	  speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'), 
 *	  timeout: Time between the fades in milliseconds (Default: '2000'), 
 *	  type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
 * 		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
 *	  runningclass: CSS-Class which the container getŐs applied (Default: 'innerfade'),
 *	  children: optional children selector (Default: null)
 *  }); 
 *

// ========================================================= */


(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
        		'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do { 
												current = Math.floor ( Math.random ( ) * ( elements.length ) );
										} while (last == current );             
										$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}
