
jQuery.noConflict();

if (typeof  cf_launch == 'undefined' || !cf_launch  ){ var cf_launch = {}; };
if(typeof console == 'undefined'){ console = { log : function(){} } };
/*
 * 
 */
(function(jQuery) {
	jQuery.fn.extend({
				isChildOf : function(filter_string) {
					var parents = jQuery(this).parents().get();
					for (j = 0; j < parents.length; j++) {
						if (jQuery(parents[j]).is(filter_string)) {
							return true;
						}
					}
					return false;
				},
				autocompletePostal: function(urlOrData, options) {
					var isUrl = typeof urlOrData == "string";
					options = jQuery.extend({}, jQuery.AutocompletePC.defaults, {
						url: isUrl ? urlOrData : null,
						data: isUrl ? null : urlOrData,
						delay: isUrl ? jQuery.AutocompletePC.defaults.delay : 10,
						max: options && !options.scroll ? 10 : 150
					}, options);
					
					// if highlight is set to false, replace it with a do-nothing function
					options.highlight = options.highlight || function(value) { return value; };
					
					// if the formatMatch option is not specified, then use formatItem for backwards compatibility
					options.formatMatch = options.formatMatch || options.formatItem;
					
					return this.each(function() {
						new jQuery.AutocompletePC(this, options);
					});
				},
				result: function(handler) {
					return this.bind("result", handler);
				},
				search: function(handler) {
					return this.trigger("search", [handler]);
				},
				flushCache: function() {
					return this.trigger("flushCache");
				},
				setOptions: function(options){
					return this.trigger("setOptions", [options]);
				},
				unautocomplete: function() {
					return this.trigger("unautocomplete");
				}
			});
})(jQuery);


jQuery.AutocompletePC = function(input, options) {

	var KEY = {
		UP: 38,
		DOWN: 40,
		DEL: 46,
		TAB: 9,
		RETURN: 13,
		ESC: 27,
		COMMA: 188,
		PAGEUP: 33,
		PAGEDOWN: 34,
		BACKSPACE: 8
	};

	// Create jQuery object for input element
	var jqryInput = jQuery(input).attr("autocomplete", "off").addClass(options.inputClass);

	var timeout;
	var previousValue = "";
	var cache = jQuery.AutocompletePC.Cache(options);
	var hasFocus = 1;
	var lastKeyPressCode;
	var config = {
		mouseDownOnSelect: false
	};
	var select = jQuery.AutocompletePC.Select(options, input, selectCurrent, config);
	
	var blockSubmit;
	
	// prevent form submit in opera when selecting with return key
	jQuery.browser.opera && jQuery(input.form).bind("submit.autocomplete", function() {
		if (blockSubmit) {
			blockSubmit = false;
			return false;
		}
	});
	
	// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
	jqryInput.bind((jQuery.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
		// track last key pressed
		lastKeyPressCode = event.keyCode;
		switch(event.keyCode) {
		
			case KEY.UP:
				event.preventDefault();
				if ( select.visible() ) {
					select.prev();
				} else {
					onChange(0, true);
				}
				break;
				
			case KEY.DOWN:
				event.preventDefault();
				if ( select.visible() ) {
					select.next();
				} else {
					onChange(0, true);
				}
				break;
				
			case KEY.PAGEUP:
				event.preventDefault();
				if ( select.visible() ) {
					select.pageUp();
				} else {
					onChange(0, true);
				}
				break;
				
			case KEY.PAGEDOWN:
				event.preventDefault();
				if ( select.visible() ) {
					select.pageDown();
				} else {
					onChange(0, true);
				}
				break;
			
			// matches also semicolon
			case options.multiple && jQuery.trim(options.multipleSeparator) == "," && KEY.COMMA:
			case KEY.TAB:
			case KEY.RETURN:
				if( selectCurrent() ) {
					// stop default to prevent a form submit, Opera needs special handling
					event.preventDefault();
					blockSubmit = true;
					return false;
				}
				break;
				
			case KEY.ESC:
				select.hide();
				break;
				
			default:
				clearTimeout(timeout);
				timeout = setTimeout(onChange, options.delay);
				break;
		}
	}).focus(function(){
		// track whether the field has focus, we shouldn't process any
		// results if the field no longer has focus
		hasFocus++;
	}).blur(function() {
		hasFocus = 0;
		if (!config.mouseDownOnSelect) {
			hideResults();
		}
	}).click(function() {
		// show select when clicking in a focused field
		if ( hasFocus++ > 1 && !select.visible() ) {
			onChange(0, true);
		}
	}).bind("search", function() {
		// TODO why not just specifying both arguments?
		var fn = (arguments.length > 1) ? arguments[1] : null;
		function findValueCallback(q, data) {
			var result;
			if( data && data.length ) {
				for (var i=0; i < data.length; i++) {
					if( data[i].result.toLowerCase() == q.toLowerCase() ) {
						result = data[i];
						break;
					}
				}
			}
			if( typeof fn == "function" ) fn(result);
			else jqryInput.trigger("result", result && [result.data, result.value]);
		}
		jQuery.each(trimWords(jqryInput.val()), function(i, value) {
			request(value, findValueCallback, findValueCallback);
		});
	}).bind("flushCache", function() {
		cache.flush();
	}).bind("setOptions", function() {
		jQuery.extend(options, arguments[1]);
		// if we've updated the data, repopulate
		if ( "data" in arguments[1] )
			cache.populate();
	}).bind("unautocomplete", function() {
		select.unbind();
		jqryInput.unbind();
		jQuery(input.form).unbind(".autocomplete");
	});
	
	
	function selectCurrent() {
		var selected = select.selected();
		if( !selected )
			return false;
		
		var v = selected.result;
		previousValue = v;
		
		if ( options.multiple ) {
			var words = trimWords(jqryInput.val());
			if ( words.length > 1 ) {
				v = words.slice(0, words.length - 1).join( options.multipleSeparator ) + options.multipleSeparator + v;
			}
			v += options.multipleSeparator;
		}
		
		jqryInput.val(v);
		hideResultsNow();
		jqryInput.trigger("result", [selected.data, selected.value]);
		return true;
	}
	
	function onChange(crap, skipPrevCheck) {
		if( lastKeyPressCode == KEY.DEL ) {
			select.hide();
			return;
		}
		
		var currentValue = jqryInput.val();
		
		if ( !skipPrevCheck && currentValue == previousValue )
			return;
		
		previousValue = currentValue;
		
		currentValue = lastWord(currentValue);
		if ( currentValue.length >= options.minChars) {
			jqryInput.addClass(options.loadingClass);
			if (!options.matchCase)
				currentValue = currentValue.toLowerCase();
			request(currentValue, receiveData, hideResultsNow);
		} else {
			stopLoading();
			select.hide();
		}
	};
	
	function trimWords(value) {
		if ( !value ) {
			return [""];
		}
		var words = value.split( options.multipleSeparator );
		var result = [];
		jQuery.each(words, function(i, value) {
			if ( jQuery.trim(value) )
				result[i] = jQuery.trim(value);
		});
		return result;
	}
	
	function lastWord(value) {
		if ( !options.multiple )
			return value;
		var words = trimWords(value);
		return words[words.length - 1];
	}
	
	// fills in the input box w/the first match (assumed to be the best match)
	// q: the term entered
	// sValue: the first matching result
	function autoFill(q, sValue){
		// autofill in the complete box w/the first match as long as the user hasn't entered in more data
		// if the last user key pressed was backspace, don't autofill
		if( options.autoFill && (lastWord(jqryInput.val()).toLowerCase() == q.toLowerCase()) && lastKeyPressCode != KEY.BACKSPACE ) {
			// fill in the value (keep the case the user has typed)
			jqryInput.val(jqryInput.val() + sValue.substring(lastWord(previousValue).length));
			// select the portion of the value not typed by the user (so the next character will erase)
			jQuery.AutocompletePC.Selection(input, previousValue.length, previousValue.length + sValue.length);
		}
	};

	function hideResults() {
		clearTimeout(timeout);
		timeout = setTimeout(hideResultsNow, 200);
	};

	function hideResultsNow() {
		var wasVisible = select.visible();
		select.hide();
		clearTimeout(timeout);
		stopLoading();
		if (options.mustMatch) {
			// call search and run callback
			jqryInput.search(
				function (result){
					// if no value found, clear the input box
					if( !result ) {
						if (options.multiple) {
							var words = trimWords(jqryInput.val()).slice(0, -1);
							jqryInput.val( words.join(options.multipleSeparator) + (words.length ? options.multipleSeparator : "") );
						}
						else
							jqryInput.val( "" );
					}
				}
			);
		}
		if (wasVisible)
			// position cursor at end of input field
			jQuery.AutocompletePC.Selection(input, input.value.length, input.value.length);
	};

	function receiveData(q, data) {
		if ( data && data.length && hasFocus ) {
			stopLoading();
			select.display(data, q);
			autoFill(q, data[0].value);
			select.show();
		} else {
			hideResultsNow();
		}
	};

	function request(term, success, failure) {
		if (!options.matchCase)
			term = term.toLowerCase();
		var alldata = cache.load(term);
		
		var currentlanguage = jQuery("html").attr("lang");
		var data = [];
		for(var i=0;i<alldata.length;i++){
			if(alldata[i].data.l ==  currentlanguage || alldata[i].data.l == 'both'){ data.push(alldata[i]); }
		}

		// recieve the cached data
		if (data && data.length) {
			success(term, data);
		// if an AJAX url has been supplied, try loading the data now
		} else if( (typeof options.url == "string") && (options.url.length > 0) ){
			
			var extraParams = {
				timestamp: +new Date()
			};
			jQuery.each(options.extraParams, function(key, param) {
				extraParams[key] = typeof param == "function" ? param() : param;
			});
			
			jQuery.ajax({
				// try to leverage ajaxQueue plugin to abort previous requests
				mode: "abort",
				// limit abortion to this input
				port: "autocomplete" + input.name,
				dataType: options.dataType,
				url: options.url,
				data: jQuery.extend({
					q: lastWord(term),
					limit: options.max
				}, extraParams),
				success: function(data) {
					var parsed = options.parse && options.parse(data) || parse(data);
					cache.add(term, parsed);
					success(term, parsed);
				}
			});
		} else {
			// if we have a failure, we need to empty the list -- this prevents the the [TAB] key from selecting the last successful match
			select.emptyList();
			failure(term);
		}
	};
	
	function parse(data) {
		var parsed = [];
		var rows = data.split("\n");
		for (var i=0; i < rows.length; i++) {
			var row = jQuery.trim(rows[i]);
			if (row) {
				row = row.split("|");
				parsed[parsed.length] = {
					data: row,
					value: row[0],
					result: options.formatResult && options.formatResult(row, row[0]) || row[0]
				};
			}
		}
		return parsed;
	};

	function stopLoading() {
		jqryInput.removeClass(options.loadingClass);
	};

};
 
jQuery.AutocompletePC.defaults = {
	inputClass: "autosuggestInput",
	resultsClass: "autosuggestResults",
	loadingClass: "ac_loading",
	minChars: 1,
	delay: 400,
	matchCase: false,
	matchSubset: true,
	matchContains: true,
	cacheLength: 10,
	max: 80,
	mustMatch: false,
	extraParams: {},
	selectFirst: true,
	formatItem: function(row) { return row[0]; },
	formatMatch: null,
	autoFill: false,
	width: 0,
	multiple: false,
	multipleSeparator: ", ",
	highlight: function(value, term) {
		return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), '<span class="match">$1</span>');
	},
    scroll: true,
    scrollHeight: 180
};

jQuery.AutocompletePC.Cache = function(options) {

	var data = {};
	var length = 0;
	
	function matchSubset(s, sub) {
		if (!options.matchCase) 
			s = s.toLowerCase();
		var i = s.indexOf(sub);
		if (i == -1) return false;
		return i == 0 || options.matchContains;
	};
	
	function add(q, value) {
		if (length > options.cacheLength){
			flush();
		}
		if (!data[q]){ 
			length++;
		}
		data[q] = value;
	}
	
	function populate(){
		if( !options.data ) return false;
		// track the matches
		var stMatchSets = {},
			nullData = 0;

		// no url was specified, we need to adjust the cache length to make sure it fits the local data store
		if( !options.url ) options.cacheLength = 1;
		
		// track all options for minChars = 0
		stMatchSets[""] = [];
		
		// loop through the array and create a lookup structure
		for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
			var rawValue = options.data[i];
			// if rawValue is a string, make an array otherwise just reference the array
			rawValue = (typeof rawValue == "string") ? [rawValue] : rawValue;
			
			var value = options.formatMatch(rawValue, i+1, options.data.length);
			if ( value === false )
				continue;
				
			var firstChar = (value)? value.charAt(0).toLowerCase() : '' ;
			// if no lookup array for this character exists, look it up now
			if( !stMatchSets[firstChar] ) 
				stMatchSets[firstChar] = [];

			// if the match is a string
			var row = {
				value: value,
				data: rawValue,
				result: options.formatResult && options.formatResult(rawValue) || value
			};
			
			// push the current match into the set list
			stMatchSets[firstChar].push(row);

			// keep track of minChars zero items
			if ( nullData++ < options.max ) {
				stMatchSets[""].push(row);
			}
		};

		// add the data items to the cache
		jQuery.each(stMatchSets, function(i, value) {
			// increase the cache size
			options.cacheLength++;
			// add to the cache
			add(i, value);
		});
	}
	
	// populate any existing data
	setTimeout(populate, 25);
	
	function flush(){
		data = {};
		length = 0;
	}
	
	return {
		flush: flush,
		add: add,
		populate: populate,
		load: function(q) {
			if (!options.cacheLength || !length)
				return null;
			/* 
			 * if dealing w/local data and matchContains than we must make sure
			 * to loop through all the data collections looking for matches
			 */
			if( !options.url && options.matchContains ){
				// track all matches
				var csub = [];
				// loop through all the data grids for matches
				for( var k in data ){
					// don't search through the stMatchSets[""] (minChars: 0) cache
					// this prevents duplicates
					if( k.length > 0 ){
						var c = data[k];
						jQuery.each(c, function(i, x) {
							// if we've got a match, add it to the array
							if (matchSubset(x.value, q)) {
								csub.push(x);
							}
						});
					}
				}				
				return csub;
			} else 
			// if the exact item exists, use it
			if (data[q]){
				return data[q];
			} else
			if (options.matchSubset) {
				for (var i = q.length - 1; i >= options.minChars; i--) {
					var c = data[q.substr(0, i)];
					if (c) {
						var csub = [];
						jQuery.each(c, function(i, x) {
							if (matchSubset(x.value, q)) {
								csub[csub.length] = x;
							}
						});
						return csub;
					}
				}
			}
			return null;
		}
	};
};

jQuery.AutocompletePC.Select = function (options, input, select, config) {
	var CLASSES = {
		ACTIVE: "suggestHover",
		OPTED: "suggestOpted"
	};
	
	var listItems,
		active = -1,
		data,
		term = "",
		needsInit = true,
		element,
		list;
	
	// Create results
	function init() {
		
	
		if (!needsInit)
			return;
		resultElement = jQuery('#search-text-result').get(0), // element to display result in
		element = jQuery(resultElement);

		list = jQuery("<ul/>").appendTo(element).mouseover( function(event) {
			if(target(event).nodeName && target(event).nodeName.toUpperCase() == 'LI') {
	            active = jQuery("li", list).removeClass(CLASSES.ACTIVE).index(target(event));
	            jQuery(target(event)).addClass(CLASSES.ACTIVE);            
	        }
		}).click(function(event) {
			jQuery(target(event)).addClass(CLASSES.ACTIVE);
			select();
			// TODO provide option to avoid setting focus again after selection? useful for cleanup-on-focus
			input.focus();
			return false;
		}).mousedown(function() {
			config.mouseDownOnSelect = true;
		}).mouseup(function() {
			config.mouseDownOnSelect = false;
		});
		
		//if( options.width > 0 )
		//	element.css("width", options.width);
			
		needsInit = false;
	} 	
	
	
	
	function target(event) {
		var element = event.target;
		while(element && element.tagName != "LI")
			element = element.parentNode;
		// more fun with IE, sometimes event.target is empty, just ignore it then
		if(!element)
			return [];
		return element;
	}

	function moveSelect(step) {
		listItems.slice(active, active + 1).removeClass(CLASSES.ACTIVE);
		movePosition(step);
        var activeItem = listItems.slice(active, active + 1).addClass(CLASSES.ACTIVE);
        if(options.scroll) {
            var offset = 0;
            listItems.slice(0, active).each(function() {
				offset += this.offsetHeight;
			});
            if((offset + activeItem[0].offsetHeight - list.scrollTop()) > list[0].clientHeight) {
                list.scrollTop(offset + activeItem[0].offsetHeight - list.innerHeight());
            } else if(offset < list.scrollTop()) {
                list.scrollTop(offset);
            }
        }
	};
	
	function movePosition(step) {
		active += step;
		if (active < 0) {
			active = listItems.size() - 1;
		} else if (active >= listItems.size()) {
			active = 0;
		}
	}
	
	function limitNumberOfItems(available) {
		return options.max && options.max < available
			? options.max
			: available;
	}
	
	function fillList() {

		list.empty();
		var max = limitNumberOfItems(data.length);
		
		for (var i=0; i < max; i++) {
			if (!data[i])
				continue;
			var formatted = options.formatItem(data[i].data, i+1, max, data[i].value, term);
			if ( formatted === false )
				continue;
			var li = jQuery("<li/>").html( options.highlight(formatted, term) ).addClass(i%2 == 0 ? "ac_even" : "ac_odd").appendTo(list)[0];
			jQuery.data(li, "ac_data", data[i]);
		}
		listItems = list.find("li");
		if ( options.selectFirst ) {
			listItems.slice(0, 1).addClass(CLASSES.ACTIVE);
			active = 0;
		}
		// apply bgiframe if available
		if ( jQuery.fn.bgiframe )
			list.bgiframe();
	}
	
	return {
		display: function(d, q) {
			init();
			data = d;
			term = q;
			fillList();
		},
		next: function() {
			moveSelect(1);
		},
		prev: function() {
			moveSelect(-1);
		},
		pageUp: function() {
			if (active != 0 && active - 8 < 0) {
				moveSelect( -active );
			} else {
				moveSelect(-8);
			}
		},
		pageDown: function() {
			if (active != listItems.size() - 1 && active + 8 > listItems.size()) {
				moveSelect( listItems.size() - 1 - active );
			} else {
				moveSelect(8);
			}
		},
		hide: function() {
			element && element.hide();
			listItems && listItems.removeClass(CLASSES.ACTIVE);
			active = -1;
		},
		visible : function() {
			return element && element.is(":visible");
		},
		current: function() {
			return this.visible() && (listItems.filter("." + CLASSES.ACTIVE)[0] || options.selectFirst && listItems[0]);
		},
		show: function() {
			var offset = jQuery(input).offset();
			element.css({
				//width: typeof options.width == "string" || options.width > 0 ? options.width : jQuery(input).width(),
				// top: offset.top + input.offsetHeight,
				left: "0px"
			}).show();
            if(options.scroll) {
                list.scrollTop(0);
                list.css({
					maxHeight: options.scrollHeight,
					overflow: 'auto'
				});
				
                if(jQuery.browser.msie && typeof document.body.style.maxHeight === "undefined") {
					var listHeight = 0;
					listItems.each(function() {
						listHeight += this.offsetHeight;
					});
					var scrollbarsVisible = listHeight > options.scrollHeight;
                    list.css('height', scrollbarsVisible ? options.scrollHeight : listHeight );
					if (!scrollbarsVisible) {
						// IE doesn't recalculate width when scrollbar disappears
						listItems.width( list.width() - parseInt(listItems.css("padding-left")) - parseInt(listItems.css("padding-right")) );
					}
                }
                
            }
		},
		selected: function() {
			var selected = listItems && listItems.filter("." + CLASSES.ACTIVE).removeClass(CLASSES.ACTIVE);
			return selected && selected.length && jQuery.data(selected[0], "ac_data");
		},
		emptyList: function (){
			list && list.empty();
		},
		unbind: function() {
			element && element.remove();
		}
	};
};

jQuery.AutocompletePC.Selection = function(field, start, end) {
	if( field.createTextRange ){
		var selRange = field.createTextRange();
		selRange.collapse(true);
		selRange.moveStart("character", start);
		selRange.moveEnd("character", end);
		selRange.select();
	} else if( field.setSelectionRange ){
		field.setSelectionRange(start, end);
	} else {
		if( field.selectionStart ){
			field.selectionStart = start;
			field.selectionEnd = end;
		}
	}
	field.focus();
};

jQuery.fn.outerHTML = function(s) {
	return (s)
	? this.before(s).remove()
	: jQuery("<p>").append(this.eq(0).clone()).html();
};
/*
 * 
 */
cf_launch.merge = function(){
	var o=arguments[0], a = arguments,p;
	for(var i=1, l=a.length; i<l; i++){
		for(p in a[i]){
			o[p] = a[i][p];
		}
	}
	return o;
};

cf_launch.initialize = function(o, selector, options){
	if (selector == false) {
		var c = new o(false, options);
	}
	else {
		jQuery(selector).each(function(){
			var c = new o(this, options);
			if (typeof c.controllerName != 'undefined') {
				this[c.controllerName] = c;
			}
		});
	}
}
cf_launch.Overlayer = function(elm,options){
	this.elm = elm;
	this.options = options;
	this.init();

}
cf_launch.Overlayer.isOpen = function(){
	return (jQuery('#overlayBase').css('display') == 'block');
}
cf_launch.Overlayer.prototype = {
	init: function(){
		if (this.elm != false) {
			jQuery(this.elm).bind("click", this, this._clickHandler);
		}
		jQuery('#overlayBase ' + this.options.overlayer + ' .close').click(this._hide);
		jQuery('#overlayBase ' + this.options.overlayer + ' .abort').click(this._hide);
		jQuery('#overlayBase ' + this.options.overlayer + ' .footer a').click(this._hide);
		
		/* uncheck radio buttons */
		jQuery("#overlayBase input[type='radio']").removeAttr('checked');
		
		if(typeof this.options.closeKey != 'undefined'){
			jQuery(document).bind("keypress",this,  
				function(e){ 
					 var code = (e.keyCode ? e.keyCode : e.which);
					 var o = e.data;
					 if(code == o.options.closeKey) { 
						 o._hide(e);
					 }
				} 
			);
		}
	},
	_clickHandler: function(e){
		e.preventDefault();
		var o = e.data;
		o._displayBlock(o.options.overlayer);
	},
	_displayBlock: function(blockClass){
		jQuery("html").addClass("jsPop");
		jQuery('#overlayBase').css('display','block');
		var arrChildren = jQuery('#overlayBase').children();
		
		arrChildren.filter(blockClass).css('display','block').focus();
		arrChildren.filter("#overlayBG").css('display','block');
	},
	_hide: function(e){
		e.preventDefault();
		jQuery('#overlayBase').css('display','none');
		var arrChildren = jQuery('#overlayBase').children();
		jQuery(arrChildren).each(function(){
			jQuery(this).css('display','none');
		});
		jQuery("html").removeClass("jsPop");		
	}
};

cf_launch.CarouselFade = function(elm, options){
	this.elm = jQuery(elm);
	this.options = {
			animate: true,
			animateRunning: false,
			autoAnimate: false, 
			duration: 1.0, 
			frequency: 3,
			activeNav:false // set nth nav active in nav, not used in prev/next nav
	};
	cf_launch.merge(this.options, options);
	this.controllerName = "_carousel";
	this._initialize();
};
cf_launch.CarouselFade.prototype = {
	_initialize: function(){
	    this.autoAnimateRunning = false;
	    var _self = this;
	    this.sections = this.elm.find('.carContent ol li').each( function(index, section) {	section._index = index; });
	    // start, stop animation
		var start =	function(){
			if(_self.options.autoAnimate){
				_self._periodicallyUpdate(_self.elm, _self.options.frequency * 1000);
			}
		};
		var stop = function(){
			if(_self.autoAnimateRunning){
				clearInterval(_self.timer);
			};
		}	    
	    //
		this.ctrlNav = this.elm.find('.carNav ul li').each( 
			function(index, section) {	
				section._index = index;
				var f = function(){
					stop();
					_self.options.autoAnimate = false;
					_self._pager(index);
				};
				jQuery(this).click(f);
			}
		);
		var activeNav = this.ctrlNav.filter(".active");
		//
		if (activeNav.length == 0) {
			this.ctrlNav.eq(0).addClass("active");
			this.sections.eq(index).show();
			this.sections.not(":first").hide();
			this.sections.children(":first").find('a').children().css('z-index','2');
			this.sections.children(":first").css('z-index','2');

		} else {
			var index = this.sections.filter(":first").eq(0).attr("_index");
			this.sections.not(":eq(" + index + ")").hide();	
		}
		this.ctrlNav.hover( 
			function(){if( cf_launch.Overlayer.isOpen() ){ return; };jQuery(this).addClass("onHover");},
			function(){if( cf_launch.Overlayer.isOpen() ){ return; };jQuery(this).removeClass("onHover");}
		);
		this.elm.hover(stop,start);
		//this.elm.find(".carContent").hover( stop,start );
		start();
        //this.sections.eq(0).find('a').css('opacity','0.5');
	},
	/**
	 * 
	 */
	_pager: function(index){
		 // navigation present ?
		 if(this.options.activeNav){
			 var an = this.ctrlNav.eq(index);
			 var ao = this.ctrlNav.filter(".active");
			 if(ao.get(0)._index == index) {return;}
		 }
		 
		 // animation callback function
		 var c = this;
		 var fn = function(){
			 // navigation present ?
			 // current or old index
			 var cIndex = (c.options.activeNav) ? ao.get(0)._index : c.sections.filter(".active").eq(0).attr("_index"); 
			 if (c.options.activeNav){
				//
				c.sections.eq(cIndex).find('a img').hide();
				c.sections.eq(cIndex).find('a span').children('span').hide();
				c.sections.eq(cIndex).hide();
				c.sections.eq(cIndex).find('a img').css('z-index','4');
				c.sections.eq(cIndex).find('a span').css('z-index','4');
			 	c.sections.eq(cIndex).css('z-index','1');
				//
				c.sections.eq(index).show();
				c.sections.eq(index).css('z-index','8');
				c.sections.eq(index).find('a img').css('z-index','8');
				c.sections.eq(index).find('a span').css('z-index','8');
				//c.sections.eq(index).find('a span.inner').fadeIn(c.options.duration * 500);
				c.sections.eq(index).find('a span').show();
				
				
			 } else {
				 c.sections.eq(index).find('a').children().show();
				 c.sections.eq(index).show();
				 c.sections.eq(cIndex).find('a').children().hide();
				 c.sections.eq(cIndex).hide();				 
			 }
			 
			 c.animateRunning = false;
		 };
		 
		 var fs = function(){
			 c.sections.eq(index).find('a img').css('z-index','1');
			 c.sections.eq(index).find('a span').children('span').css('z-index','1');
			 c.sections.eq(index).find('a img').show();
             c.sections.eq(index).find('a').css('opacity','0');
			 c.sections.eq(index).find('a span.outer').hide();
			 c.sections.eq(index).show();
			 c.sections.eq(index).css('z-index','1');
		 };
		 // start animation
		 if(this.options.animate){
			 if(!this.animateRunning){
				 this.animateRunning = true;
				 fs();
				 if(c.options.activeNav){
					 ao.removeClass("active");
					 an.addClass("active");
				 }
				 this.sections.eq(index).find('a').animate({'opacity': '1'}, this.options.duration * 1000 );
				 this.sections.eq(ao.get(0)._index).find('a img').fadeOut(this.options.duration * 500, fn);
			 }
		 }else{
			 fn();
			 this.sections.filter(".active").removeClass("active");
			 this.sections.eq(index).addClass("active");
		 }
	},
	/**
	 * 
	 */
	next: function(o){
		var obj = (typeof o != "undefined") ? jQuery(o).get(0)._carousel : this;
				
		if(obj.options.activeNav){
			// pager nav
			var ao = obj.ctrlNav.filter(".active");
			var nextIndex = 0;
			if(ao.length == 1){
				var cIndex = ao.get(0)._index;
				nextIndex = (obj.sections.length - 1 == cIndex) ? 0 : cIndex + 1;
			}
		} else {
			// prev next nav
			var cIndex = obj.sections.filter(".active").eq(0).attr("_index");
			nextIndex = (obj.sections.length - 1 == cIndex) ? 0 : cIndex + 1;
		}
		obj._pager(nextIndex);
	},
	previous: function(o){
		var obj = (typeof o != "undefined") ? jQuery(o).get(0)._carousel : this;
		if(obj.options.activeNav){
			// pager nav
			var ao = obj.ctrlNav.filter(".active");
			var nextIndex = 0;
			if(ao.length == 1){
				var cIndex = ao.get(0)._index;
				nextIndex = (cIndex === 0)? obj.sections.length - 1 : cIndex - 1;
			}
		} else {
			// prev next nav
			var cIndex = obj.sections.filter(".active").eq(0).attr("_index");
			nextIndex = (cIndex == 0)? obj.sections.length - 1 : cIndex - 1;
		}	
		obj._pager(nextIndex);
	},
	/**
	 * 
	 */
	_periodicallyUpdate: function(o,t)
	{ 
		this.autoAnimateRunning = true;
		var nextItem = function(o){
			if( cf_launch.Overlayer.isOpen() ){ return; };
			cf_launch.CarouselFade.prototype.next(jQuery(o));
		};
		this.timer = window.setInterval(function(){nextItem(o)},t);
	}
};

cf_launch.Carrousel = function(elm, options){
	this.elm = jQuery(elm);
	this.options = options;
	this.isAnimating = false;
	this.init();
};

cf_launch.Carrousel.prototype = {
	init : function (){
		var ol = this.elm.find('.carContent').children("ol");
		this.elm.find('.carContent li').bind("mouseover", this.mouseoverItemHandler);
		this.elm.find('.carContent li').bind("mouseout", this.mouseoutItemHandler);
		ol.get(0).carrousel = this;
 		this.elm.find('.carNav .prev a').bind("click", this, this.clickPrevHandler );
 		this.elm.find('.carNav .next a').bind("click", this, this.clickNextHandler );
		//
		this.animation = null;
	},
	mouseoverItemHandler : function(e) {
		jQuery(e.currentTarget).addClass('hover');
	},
	mouseoutItemHandler : function(e) {
		jQuery(e.currentTarget).removeClass('hover');
	},
	clickNextHandler : function(e){
 		e.preventDefault();
		var carrousel = e.data;
		
		if (carrousel.isAnimating == false) {
			carrousel.isAnimating = true;
			cf_launch.Carrousel.prototype.nextHandler(carrousel);
		}
	},
	nextHandler : function(o){
 		var carrousel = o;
 		var obj = carrousel.obj;
 		var ul = carrousel.elm.find('.carContent').children("ol")
		// util function called from animation complete (no argument) or "inline"
		var shiftUl = function(ul){
			for (var i = 0; i < carrousel.options.frequency; i++) {
				var ul = jQuery(ul || this);   // "inline" || animation complete
				var clone = ul.children(":first").clone(true);
				clone.removeClass("first");
				clone.addClass("last");
				ul.children(":last").removeClass("last");
				ul.append( clone );
				ul.children(":first").remove();
				ul.children(":first").addClass("first");
				ul.css({left : ul.get(0).carrousel.options.defaultLeft });
			}
			carrousel.isAnimating = false;
		}
		if (carrousel.options.animate) {
			// anim
			var slideAmount = ul.children(":eq(1)").offset().left - ul.children(":eq(0)").offset().left;
			slideAmount = slideAmount * carrousel.options.frequency;
			ul.animate({
				"left": -slideAmount
			}, {
				duration: carrousel.options.duration,
				queue: true,
				easing: "swing",
				complete: shiftUl
			});
		}
		else {
			shiftUl(ul);
		}
	},
	clickPrevHandler : function(e){
		e.preventDefault();
		var carrousel = e.data;
		if (carrousel.isAnimating == true) {
			return false;
		}
		carrousel.isAnimating = true;
		var obj = carrousel.obj;
 		var ul = carrousel.elm.find('.carContent').children("ol");
		
		var slideAmount = ul.children(":eq(1)").offset().left - ul.children(":eq(0)").offset().left;
		slideAmount = slideAmount * carrousel.options.frequency;

		// anim
		var shiftUl = function(ul){
			var clone = ul.children(":last").clone(true);
			clone.removeClass("last");
			clone.addClass("first");
			ul.children(":first").removeClass("first");
			ul.prepend( clone );
			ul.children(":last").remove();
			ul.children(":last").addClass("last");
		};
		
		var stopAnimation = function(){
			carrousel.isAnimating = false;
		}
		
		for (var i = 0; i < carrousel.options.frequency; i++) {
			shiftUl(ul);
		}
		
		ul.css({
			left: -slideAmount
		});
		
		if (carrousel.options.animate) {
			ul.animate({"left": 0}, {duration: carrousel.options.duration, queue: true, easing: "swing", complete: stopAnimation});
		}
	}
};

cf_launch.TabPane = function(elm) {
	this.elm = jQuery(elm);

	if (this.elm.hasClass('hover')) {
		this.init_hover();
	}
	else {
		this.init();	
	}
};

cf_launch.TabPane.prototype = {
	init: function(){
	    var _self = this;			
		this.elm.find('.tabNav li a').bind("click", this, this._clickHandler);
		this.elm.find('.tabMain:not(:first)').addClass('hidden');
		this.elm.find('.tabNav li:first').addClass('active');
		this.elm.find('.tabMain:first').removeClass('hidden');
	},
	_clickHandler: function(e, event) {
		e.preventDefault();	
		var o = e.data;
		
		o.elm.find('.tabNav li').removeClass('active');
		o.elm.find('.tabMain').addClass('hidden');
		
		var id = jQuery(this).attr("href");
		
		jQuery(this).parent().addClass('active');
		o.elm.find('.tabMain'+id).removeClass('hidden');
	},
	init_hover: function() {
	    var _self = this;			
		this.elm.find('.tabNav li a').bind("mouseover", this, this._hoverHandler);
		this.elm.find('.tabNav li a').each( function(index, section) {	section._index = index; });
		this.elm.find('.promo').each( function(index, section) {	section._index = index; });
		
		var activeNav = this.elm.find('.tabNav li a.active');
		
		if (activeNav.length == 0) {
			this.elm.find('.tabNav li a:first').addClass('active');
		} else {
			var id = jQuery(activeNav).attr("_index");
		
			this.elm.find('.promo').each(function(index, section) {
				var s = jQuery(section);
				if (s.attr("_index") == id) {
					s.show();
				}
				else {
					s.hide();
				}
			});
		}
	},
	_hoverHandler: function(e, event) {
		var o = e.data;
		var id = jQuery(this).attr("_index");
		
		o.elm.find('.tabNav li a').removeClass('active');
		
		jQuery(e.currentTarget).addClass('active');
		
		o.elm.find('.promo').each(function(index, section) {
			var s = jQuery(section);
			if (s.attr("_index") == id) {
				s.show();
			}
			else {
				s.hide();
			}
		});
	}
};
           

cf_launch.PostalCode = function() {
	var elm = jQuery("#searchText");
	try {
		if (typeof autosuggestPostal_data != 'undefined') {
			jQuery("#searchText").autocompletePostal(autosuggestPostal_data, {
				formatItem: function(item){
					try {
						return (item.s) ? item.s : '';
					} 
					catch (e) {
					}
				}
			}).result(function(event, item){
				jQuery("#searchText").val(item.s);
			});
		}
	} 
	catch (e) {
	}
	
	var searchForm = jQuery("#search_01");
	var s = searchForm.find(".textfield:first");
	var l = searchForm.find("label[for='" + s.attr('id') + "']");
	var b = searchForm.find(":submit:first");
	
	b.attr("disabled", "disabled")
	l.show();
	s.val("");
	
	s.focus(function(){
		l.hide();
	});
	
	s.blur(function(event){
		if (s.val().length < 1) {
			l.show();
		}
	});
	
	s.keyup(function(event){
		l.hide();
		(s.val().length > 0) ? b.removeAttr("disabled") : b.attr("disabled", "disabled");
	});
	
};

cf_launch.Newsletter = function() {
	var cardNr = jQuery('#cardNr');
	var placeholder = jQuery('#newsletterForm').find("label[for='cardNr']");;
	
	cardNr.attr('disabled', true);
	cardNr.addClass('disabled');
	cardNr.focus(function(){placeholder.hide();});
	cardNr.blur(function(){if( cardNr.val().length < 1){placeholder.show();}});
	
	//jQuery('#newsletterForm #formcontent-cardholder :radio').bind("click", cardNr, cf_launch.Newsletter._clickRadioHandler);
	var el = jQuery('#formcontent-cardholder').find(":radio");
	el.bind("click", cardNr, cf_launch.Newsletter._clickRadioHandler);
	
	jQuery('#newsletterForm').submit(cf_launch.Newsletter._submitHandler);
};

cf_launch.Newsletter._clickRadioHandler = function(e) {
	var cardNr = e.data;
	var t = jQuery(e.target);
	if( t.closest(".control").find(".subordinate").length > 0 ){
		cardNr.removeAttr('disabled');
		cardNr.removeClass('disabled');	
	} else {
		cardNr.attr('disabled', true);
		cardNr.addClass('disabled');
	}
};

cf_launch.Newsletter._fadeOutCallback = function(e) {
	jQuery('#overlayBase').css('display','none');
	jQuery("html").removeClass("jsPop");
}

cf_launch.Newsletter._submitHandler = function(e) {
	var postData = jQuery('#newsletterForm').serializeArray();
	var url = 'libinc/inc_newsletter_process.cfm';
	
	jQuery.post(url, postData,
	  function(data){
	  	if (data.success == true) {
			// Hide all overlays
			jQuery('#overlayBase .popSubscribe').css('display','none');
			
			// Show subscribe done overlay
			jQuery('#overlayBase .popSubscribeDone').css('display','block').focus();
			setTimeout(function(){
				// Auto hide overlay
				jQuery('#overlayBase .popSubscribeDone').fadeOut("slow", cf_launch.Newsletter._fadeOutCallback);
			}, 6000);
		}
		else {
			// Show form with validation errors
			jQuery('#overlayBase .popSubscribe').html(data.form);
			cf_launch.initialize(cf_launch.Overlayer, false, {overlayer: ".popSubscribe"});
			Cufon.set('fontFamily', 'Omnes500').replace('.popSubscribe h2.heading span');
			cf_launch.Newsletter();
		}
	  }, "json"
	);
	
	return false;
};

cf_launch.Shoplist = function() {
	jQuery('.shopList .pop').hide();
	jQuery('.shopList a').bind('mouseover', this, cf_launch.Shoplist._shopListMouseOver);
	jQuery('.shopList a').bind('mouseout', this, cf_launch.Shoplist._shopListMouseOut);
	jQuery('.shopList .pop').bind('mouseover', this, cf_launch.Shoplist._shopListPopMouseOver);
	jQuery('.shopList .pop').bind('mouseout', cf_launch.Shoplist._shopListPopMouseOut);
}

cf_launch.Shoplist._shopListPopMouseOver = function(e) {
	o = e.data;
	clearTimeout(o.timer);
};

cf_launch.Shoplist._shopListPopMouseOut = function(e) {
	o.timer = setTimeout(function(){
		jQuery('.shopList .pop').hide();
	}, 50);
};

cf_launch.Shoplist._shopListMouseOver = function(e) {
	o = e.data;
	jQuery('.shopList .pop').hide();
	jQuery(e.currentTarget).siblings('div .pop').show();
	if (typeof o.timer != 'undefined') {
		clearTimeout(o.timer);
	}
};

cf_launch.Shoplist._shopListMouseOut = function(e) {
	o = e.data;
	o.timer = setTimeout(function(){
		jQuery(e.currentTarget).siblings('div .pop').hide()
	}, 50);
};

 

// clean loading of carousel images
document.write("<style>#carousel_01 .carContent li.first a img { z-index:8; } #carousel_01 .carContent li.first a span { z-index:8; }</style>");

// Cufon.replace('h2', {});
Cufon.set('fontFamily', 'Omnes700').replace('.services h2.heading span')('.brands h2.heading span')('.recipes h2.heading span')('.promoFolders h2.heading span')('.promoList h2.heading span')('.newsletter h2.heading span')('.focusJobs h2.heading span')('.focusNews h2.heading span')('.focusHelp h2.heading span');
Cufon.set('fontFamily', 'Omnes500').replace('.popSubscribe h2.heading span')('.popSubscribeDone .header h2.heading span');
Cufon.set('fontFamily', 'Omnes500').replace('.locator .content h1.heading span');

jQuery(document).ready(function() {
  try { Cufon.now(); } catch(e){}
	var animD = ( jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 9) ? 0 : 1;
	cf_launch.initialize(cf_launch.CarouselFade, "#carousel_01",  {autoAnimate: true, frequency: 3, duration: animD, activeNav:true });
	cf_launch.initialize(cf_launch.Carrousel, "#carousel_02",  {animate: true, duration: 300, frequency: 3, defaultLeft: "0px"});
	cf_launch.initialize(cf_launch.TabPane, ".tabpane");
	cf_launch.initialize(cf_launch.Overlayer, '#showPopupSubscribe', {overlayer: ".popSubscribe"});
	cf_launch.initialize(cf_launch.Overlayer, '#showPopupStores', {overlayer: ".popStores"});
	cf_launch.initialize(cf_launch.Overlayer, '#showPopupEshop', {overlayer: ".popEshop"});
	cf_launch.initialize(cf_launch.Overlayer, false, {overlayer: ".popSubscribeDone"});
	cf_launch.PostalCode();
	cf_launch.Newsletter();
	cf_launch.Shoplist();
});


