(function($) {
	if (typeof($.brad) !== "object") { $.brad = {}; }

	$.brad.page = {
		isHomePage: false,
		isShop: true,
		
		init: function () {
			var $body = $("body"),
				languageResourceEnabled = false,
				disableLinkHTML = "",
				$homePage = $("#homePageShop"),
				// variables for supports section
				pageH1Array, pageH1ArrayLength, $pageH1,
				pageH1Word, pageH1Modified = "", pageH1Wrapped = false;
				
			$body.removeClass("noJs");
			

			if ($.isFunction($.getText)) {
				languageResourceEnabled = true;
			
				// Add accessibility warning message
				disableLinkHTML = "<a href='?disableFn=1' title=''>"+$.getText("accessibilityLink")+"</a>";
				$body.prepend("<p class='accessAlt'>"+$.getText("accessibilityMsg")+disableLinkHTML+"</p>");
				
				// disable accessibility fn (functions)?
				/*global window */
				if (window.location.search.indexOf("disableFn=1") !== -1) {
					$.brad.disableFn();	
				}
			}
			
			if ($homePage.length) {
				this.isHomePage = true;
				this.runHomePage();
			} else {
				this.runHomePage();				

				// *** exception routines for support sections ***
				this.isShop = $body.find(".shopSection:first").length > 0? true: false;				
				if (!this.isShop) {
					$body.find("h1").each(function() {
						$pageH1 = $(this);
						pageH1Array = $pageH1.text().split(" : ");
						pageH1ArrayLength = pageH1Array.length;
						if (pageH1ArrayLength > 1) {
							for (pageH1Word=0;pageH1Word<pageH1ArrayLength;pageH1Word++) {
								if (pageH1Word > 0 && !pageH1Wrapped) {
									pageH1Modified += '<span class="accessAlt noTextTransform"> : ';
									pageH1Wrapped = true;
								}
								pageH1Modified += pageH1Array[pageH1Word];
								if ((pageH1Word == pageH1ArrayLength-1) && pageH1Wrapped) {
									pageH1Modified += '<\/span>';	
								}
							}
							$pageH1.html(pageH1Modified);	
						}						
					});
				}

				// list of routines to render the page that can be re-called (in Ajax for instance)
				this.render();
				
				// Scrollers
				$(".hScrollBarJs").scroller({fillSpace:false, toggle: true});
				
				// Content Displayer
				$(".cTabs").contentDisplayer();
				$(".pkgToggle.tglBoxJs").contentDisplayer();
	
				// Flyouts
				$(".flyOutInputsJs").flyOut({inputs:true});			
				$(".flyOutAjaxHelpLinksJs").flyOut({ajax:true, className:"helpPanel"});
				
				// lightBoxes 
				$(".decisionLightBoxJs,.lightBoxInPageJs").lightBox();
				$(".emailFriendJs").lightBox({colClassName:"col8"});
				$(".lightBoxImageJs").lightBox({image:true});
				$(".channelLightBoxJs").lightBox({ajax:true, minWidth: 224, colClassName:'col5'});
				$(".extDecisionLightBoxJs, .lightBoxAjaxJs").lightBox({ajax:true});				
				$(".inPageGreyMarketToolJs").lightBox({colClassName:"col10"});
				$(".extGreyMarketToolJs").lightBox({ajax:true, colClassName:"col10"});
				
				// text Breaker (this needs to be placed before tabbings declaration)
				$(".secNav").textBreaker();
				$(".hTabs").textBreaker();
				
				// tabs
				$(".tabsJs").tabbing();
				$(".tabTrigSet li a").append("<span class='tabExtra1'></span><span class='tabExtra2'></span><span class='tabExtra3'></span><span class='tabExtra4'></span>");
				
				// Compare Table
				$("td:first",".compareTbl tr").each(function() {
					$(this).width($(this).width());
				});	
				
				// outLineKiller
				$(".buttonize, .ttTrigger, .tabTrigSet ul li a, .secNav ul li a, .bt_addCompare, .pageCounter ul li a, .pkgToggle ul li a").outLineKiller();
	
				// Remove Table Column
				$(".tableColumnRemoverJs").tableColumnRemover();
	
				// collaspe/uncollaspe in compare table
				$(".pkgToggle").collapser();

				// Open link in new browser window
				$(".newSbWinJs").live("click", function() {
					$.popup.open(this, { 
						width: 698, 
						height: $(window).height()-$(window).height()/3,
						toolBar: false,
						location: true,
						status: true,
						menuBar: false, 
						scrollBars: true,
						resizable: true
					});
					return false;
				});

				// Compare Tool			
				$(".bt_addCompare").live("click",function() {
					$.compareTool.show(this);
					return false;
				});	
				
				// To Remove
				$(".bt_remove").live("click",function() {
					$.toRemove.remove($(this));
					return false;
				});
				
				$('.seeMoreLink').wrapInner('<span></span>').append('<span class="seeMoreLinkExtra"><!-- --></span>');
			}
		},
		render: function(context, useCase) {
			if (typeof(context) === "undefined") {
				context = "body";
			}
			$.brad.renderSelector = context;
			
			// Optimisation only: everything can go in default
			switch(useCase) {
				case "lightBox":
					this.frontEnd.fonts(context);
					this.frontEnd.boxes(context);
					this.frontEnd.buttons(context);
					this.frontEnd.datePicker(context);
					$(".lbTitle a", context).outLineKiller();
					$(".hScrollBarJs", context).scroller({fillSpace:true, toggle: false});

					this.frontEnd.misc(context);
					break;
				case "scroller":
					this.frontEnd.fonts(context);				
					this.frontEnd.buttons(context);
					this.frontEnd.itemGroup(context);
					this.frontEnd.quickViews(context);
					this.frontEnd.pricingFormats(context);					
					break;
					
				case "summaryBox":
					this.frontEnd.boxes(context);				
					this.frontEnd.buttons(context);
					break;
					
				case "sBuilderStepTV":
					this.frontEnd.buttons(context);
					this.frontEnd.capsules(context);
					this.frontEnd.itemGroup(context);					
					break;

				case "sBuilderStepHome":
				case "sBuilderStepInternet":
					this.frontEnd.buttons(context);
					this.frontEnd.capsules(context);
					$(context).find(".vSpacer:last").remove();										
					break;

				case "sBuilderStepMobility":				
					this.frontEnd.buttons(context);
					this.frontEnd.capsules(context);
					this.frontEnd.carousel(context);
					this.frontEnd.fonts(context);
					this.frontEnd.itemGroup(context);
					this.frontEnd.pricingFormats(context);
					this.frontEnd.toggleShowHide(context);
					break;
					
				case "sBuilderStepTitle":
					this.frontEnd.fonts(context);				
					break;

				case "quickview":
					this.frontEnd.fonts(context);
					this.frontEnd.buttons(context);
					this.frontEnd.carousel(context);
					this.frontEnd.pricingFormats(context);
					this.frontEnd.itemGroup(context);
					break;

				default:
					this.frontEnd.fonts(context);
					this.frontEnd.boxes(context);
					this.frontEnd.tables(context);
					this.frontEnd.buttons(context);
					this.frontEnd.capsules(context);
					this.frontEnd.misc(context);	

			}
			// execute any callBacks
			if ($.isFunction($.runCallBack)) {
				$.runCallBack(arguments);
			}
		},
		ready : function() {
			$.brad.navigation.primary.init();

			if (!this.isHomePage) {
				// Arrange Margins
				// Note Arrange margins MUST BE PLACE BEFORE EQUALIZE
				$.itemGroupLayouting();
				
				// Equalizing: we put the equalize process in page.ready e.g when everything
				// is loaded in the page because some browsers cannot access image dimension
				// when the image is not fully loaded
				$(".cBox").equalize({similarItem:"unit"});
				$(".stepList").equalize({similarItem:"eqJs"});
				$(".eqJs").parents(".refLine").equalize({similarItem: "eqJs"});
	
				if ($(".capsule:first").length) {
					$(".refLine .refLine").equalize({similarItem:"eqJs"});
					$(".refLine").equalize({similarItem:"unit"});
				}	
			}
		},
		elementFinder: function(selector) {
			var context = $.brad.renderSelector;
			switch(typeof(context)) {
				case "object":
					selector = $(context).find(selector);
					break;
				case "string":
					if (context.indexOf("#") !== -1 || context.indexOf(".") !== -1) {
						selector = context+" "+selector;
					} else {
						selector = "body "+selector;
					}
					break;
			}
			return selector;
		},
		frontEnd: {
			boxes: function(context) {
				var $cBox, $shell, $actHighlight;
				
				// Create extra markup to display cBox structure
				$(".cBox", context).each(function() {
					$cBox = $(this);											  
					if ($cBox.find(".cBoxExtra1:first").length === 0) {
						$cBox.append('<div class="cBoxExtra1"><!-- --></div><div class="cBoxExtra2"><!-- --></div><div class="cBoxExtra3"><div class="cBoxExtra4"><!-- --></div></div><div class="cBoxExtra5"><div class="cBoxExtra6"><!-- --></div></div>');
					}
				});

				// Create extra markup to display shell structure
				$(".shell", context).each(function() {
					$shell = $(this);
					if ($shell.find(".shellExtra1:first").length === 0) {
						$shell.append('<span class="shellExtra1"><!-- --></span><span class="shellExtra2"><!-- --></span><span class="shellExtra3"><!-- --></span><span class="shellExtra4"><!-- --></span>');
					}
				});		
	
				// Create extra markup to display shell structure
				$(".actHighlight", context).each(function() {
					$actHighlight = $(this);
					if ($actHighlight.find(".liExtra1:first").length === 0) {
						$actHighlight.append('<span class="liExtra1"><!-- --></span><span class="liExtra2"><!-- --></span><span class="liExtra3"><!-- --></span><span class="liExtra4"><!-- --></span>');
					}
				});				
			},
			buttons : function(context) {
				var $child;
				
				// Create extra markup to display button structure
				$(".buttonize", context).each(function() {
					$child = $(this).children();
					if ($child.length) {
						if ($($child[0]).hasClass("accessAlt")) {
							$(this).wrapInner("<span></span>").find("span:not('.accessAlt')").append('<span><!-- --></span>');
						}
					} else {
						$(this).wrapInner("<span></span>").find("span:not('.accessAlt')").append('<span><!-- --></span>');						
					}
				}).outLineKiller();
			},
			capsules: function(context) {
				var $capsules, $capsule;
				$capsules = $(".capsule", context);
				
				// Create extra markup to display capsules structure
				if ($capsules.length) {
					$capsules.each(function() {
						$capsule = $(this);
						if ($capsule.find(".capsuleExtra1:first").length === 0) {
							$capsule.append('<span class="capsuleExtra1"><!-- --></span><span class="capsuleExtra2"><!-- --></span><span class="capsuleExtra3"><!-- --></span><span class="capsuleExtra4"><!-- --></span>');
						}
					});

					$(".refLine .refLine", context).equalize({similarItem:"eqJs"});
					$(".refLine", context).equalize({similarItem:"unit"});
				}		
			},
			carousel: function(context) {
				$(".carousel", context).carousel();				
			},
			compareWidget: function(context) {
				$(".bt_addCompare", context).compareTool();
			},
			datePicker: function(context) {
				var $inputs,
					imgPath = "/web/common/all_languages/all_regions/skin/ic_cal.gif",
					initDatePicker, lang = "";

				if ($.isFunction($.getPageLang)) {
					lang = $.getPageLang();
					lang = lang==="en"?"":lang;
				}
				$.datepicker.setDefaults($.datepicker.regional[lang]);
				
				initDatePicker = function($inputs) {
					$inputs.each(function() {
						if (!$.data(this,"datePickerInitialized")) {
							$(this).datepicker({showOn: 'both', showAnim: 'fadeIn', buttonImage: imgPath, buttonImageOnly: true});
							$.data(this,"datePickerInitialized", true);
						}
					});
				};

				$inputs = $(".datepicker", context);
				if ($inputs.length) {
					initDatePicker($inputs);	
				}
			},
			fonts : function(context) {
				// Replace page's title with Cufon text-replacement method
				/*global Cufon */
				if (typeof(Cufon) === "function" && typeof($.cookies.get("brad-cufon")) !== "string") {
					// Text replacement exceptions // put temporary away
					var $noTextTransform = $(".noTextTransform"),
						$element, $parent;
					
					$noTextTransform.each(function() {
						$element = $(this);
						$parent  = $element.parent();
						
						if ($parent.attr("id") === "") {
							$parent.attr("id","txtReplacement-"+Math.floor(Math.random()*100));
						}
						
						// Set element ID
						$element.attr("id","element-"+$parent.attr("id"));
						
						// Put text outside
						$("body").append($element);
					});
		
					// Do text replacement
					Cufon.replace($.brad.page.elementFinder("h1"));
					Cufon.replace($.brad.page.elementFinder(".txtRep"));				
					
					// Reverse text replacement exceptions
					$noTextTransform.each(function() {
						$element = $(this);
						$parent	= $("#"+$element.attr("id").replace("element-",""));
						
						// Put back content
						$parent.append($element);
					});
				}
			},
			itemGroup: function(context) {
				$.itemGroupLayouting(context);
			},
			misc: function(context) {
				var pageHTML;
				if (typeof(context) !== "undefined") {
					pageHTML = $(context).html();
				} else {
					/*global document */
					pageHTML = document.body.innerHTML;
				}
				
				// Carousel
				if (/carousel/.test(pageHTML)) {
					this.carousel(context);
				}
	
				// Accordion
				if (/hAccordion/.test(pageHTML)) {
					$(".hAccordion", context).accordion();
				}
				
				// Toggle ShowHide
				if (/tglJs/.test(pageHTML)) {
					this.toggleShowHide(context);
				}

				// Max character counter
				if (/charCountDownJs/.test(pageHTML)) {
					$(".charCountDownJs", context).maxChar();
				}

				// CompareTool
				if (/bt_addCompare/.test(pageHTML)) {
					this.compareWidget(context);
				}

				// Build pricing markup
				if (/pricingInfo/.test(pageHTML)) {
					this.pricingFormats(context);
				}
				
				// QuickView
				if (/quickViewJs/.test(pageHTML)) {
					this.quickViews(context);
				}				

				// DatePicker
				if (/datepicker/.test(pageHTML)) {
					this.datePicker(context);
				}

				// ToolTip
				if (/ttTrigger/.test(pageHTML)) {
					$(".ttTrigger", context).toolTip();
				}

				// outline Killer
				if (/tgl||bt_remove/.test(pageHTML)) {
					$(".tgl, .bt_remove", context).outLineKiller();
				}
				
				// full Scroll Detector
				if (/fTerms/.test(pageHTML)) {
					$(".fTerms", context).fullScrollDetector();
				}

				// ItemGroup margins layouting
				if (/itemGroup/.test(pageHTML)) {
					this.itemGroup(context);
				}				
			},
			pricingFormats: function(context) {
				$(".pricingInfo .priceTag", context).formatPrice();
			},
			tables: function(context) {
				// Styles added to data tables
				$("table tr:odd", context).addClass("odd");
				$("table tr:even", context).addClass("even");				
			},
			toggleShowHide: function(context) {
				// Toggle ShowHide
				$(".tglJs", context).toggleShowHide();
			},
			quickViews: function(context) {
				// QuickViews
				$(".quickViewJs", context).quickView();				
			}
		},
		runHomePage: function() {
			// put here homepage exclusive routines
			// note: these routines will also be executed on normal pages

			// Put a label over its associated text input
			$('label.labelOver').labelOver();

			// Flyouts
			$(".flyOutLinksJs").flyOut();

			// Carousel
			$(".pgFeature .carousel").carousel({navInside:true, autoPlay:true}); $(".pgFeatureAlt .carousel").carousel({navInside:true, autoPlay:true});

			// Open link in new browser window
			$(".newWinJs").live("click", function() {
				$.popup.open(this, { 
					width: $(window).width(), 
					height: $(window).height() 
				});
				return false;
			});
			
			$(".popupWinJs").live("click", function() {
				$.popup.open(this, {
					width: 1000, 
					height: 760,
					scrollBars: true, 
					toolBar: false, 
					location: false, 
					status: false, 
					menuBar: false, 
					resizable: false				
				});
				return false;
			});

			// outLineKiller
			$(".flyOutTrig, .primNav ul li a, .pgFeature a").outLineKiller();
		}
	};
	$.brad.navigation = {
		primary: {
			languageResourceEnabled: false,
			shopButtonObj: null,
			supportButtonObj: null,
			init: function() {
				var	shopOpen	= $.brad.page.isShop,
					supportOpen = shopOpen === true ? false: true,
					duration	= 600,
					$primNavShopButton		= $("#primNavShopButton"),
					$primNavSupportButton	= $("#primNavSupportButton"),
					$primNavSupportList		= $("#primNavSupportList");

				if ($primNavShopButton.length && $primNavSupportButton.length) {
					this.shopButtonObj = $primNavShopButton;
					this.supportButtonObj = $primNavSupportButton;
					
					if ($.isFunction($.getText)) { this.languageResourceEnabled = true; }
					
					$.brad.navigation.primary.setTitle(shopOpen);

					$primNavShopButton.click(function(){
						if (supportOpen){
							$primNavSupportList.animate({left: "864px"}, {duration: duration});
							shopOpen = true;
							supportOpen = false;						
							$.brad.navigation.primary.setTitle(shopOpen);
							return false;
						}
						$.brad.navigation.primary.setTitle(shopOpen);
					});
						
					$primNavSupportButton.click(function(){
						if (shopOpen){
							$primNavSupportList.animate({left: "222px"}, {duration: duration});
							shopOpen = false;
							supportOpen = true;
							$.brad.navigation.primary.setTitle(shopOpen);							
							return false;
						}
						$.brad.navigation.primary.setTitle(shopOpen);
					});
				}
			},
			setTitle: function(shopOpen) {
				if (this.languageResourceEnabled) {
					if (shopOpen) {
						this.shopButtonObj.attr("title", $.getText("goToShopHomePage"));
						this.supportButtonObj.attr("title", $.getText("openSupportMenu"));
					} else {
						this.shopButtonObj.attr("title", $.getText("openShopMenu"));
						this.supportButtonObj.attr("title", $.getText("goToSupportHomePage"));
					}
				}				
			}
		}
	};
	
	// used to add third-party interface
	$.brad.external = {
		tracker: function(params) {
			// !important: params structure MUST look like:
			// params.appName
			// params.actionName
			// params.data
			if (!$.isEmptyObject(params)) {
				switch(params.appName) {
					case "lp": // live person
						switch(params.actionName) {
							case "solutionBuilder":
								/*global lpSendData */
								if (typeof(lpSendData) === "function") {
									$.each(params.data, function(name, value) {
										lpSendData("page",name,value);	  
									});
								}
								break;
							case "lightBox":
								if (typeof(lpSendData) === "function") {									
									lpSendData('session','lightbox',params.data.state);
								}
								break;
							case "tabs":
								if (typeof(lpSendData) === "function") {
									lpSendData('page','ProductTab',params.data.tabLabel);
								}
								break;
							default:
								if (typeof(lpSendData) === "function") {
									lpSendData('page','ClickAction',params.data.componentName);
								}
						}
						break;
					case "omniture":
						switch(params.actionName) {
							case "sbSumBoxEnable":
								/*global s_oUpdateClasses*/
								if (typeof s_oUpdateClasses === "function") {
									s_oUpdateClasses();	
								}
								break;
							default:
								// add default action here if applicable							
						}
						break;
						
					// Add new appName case here
				}
			}
		}
	};
	
	// used to disable functions that may reduce accessibility
	$.brad.disableFn = function() {
		// disable cufon
		if (typeof($.cookies)==="object") {
			$.cookies.set("brad-cufon",false,365);
		}
	};

	// Dom ready
	$(function() { 
		$.brad.page.init(); 
	});
	
	// Page ready
	$(window).load(function(){ 
		$.brad.page.ready();
	});
/*global jQuery */	
})(jQuery);









/* Spacer *****************************************************/









(function($) {

/*global jQuery */
jQuery.fn.scroller = function(settings) {
	var defaults, validateParams,
		showPage, generateNavigationPager,
		languageResourceEnabled = $.isFunction($.getText),
		defToggleTitle = "Display as scroller / grid";
	
	defaults = {
		fillSpace: true,
		fillSpacePaddingRight: 120,
		showNavigation: true,
		speed: 1500,		
		toggle: false,
		toggleTitle: languageResourceEnabled?$.getText("scrollerTogglerToolTip"):defToggleTitle,
		togglerClassName: "tglBtn",
		maskContainer: "cBox",
		itemsContainer: "refLine",
		scrollerContainer: "cFoot",
		emptyClassName: "hScrollBarEmpty",
		nthClassName: "colLast",
		pagerNavigationClassName: "pageCounter",
		gridViewModeClassName: "cToggleView",
		minScrollBarWidth: 33 // pourcent 33% of the scroller width
	};
	
	settings = $.extend(false, defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.fillSpace) !== "boolean") {
			settings.fillSpace = true;
		}
		if (isNaN(settings.fillSpacePaddingRight)) {
			settings.fillSpacePaddingRight = 125;
		}
		if (typeof(settings.showNavigation) !== "boolean") {
			settings.showNavigation = true;
		}
		if (isNaN(settings.speed)) {
			settings.speed = 1500;
		}
		if (typeof(settings.toggle) !== "boolean") {
			settings.toggle = false;
		}
		if (typeof(settings.toggleTitle) !== "string") {
			settings.toggleTitle = defToggleTitle;
		}
		if (typeof(settings.togglerClassName) !== "string") {
			settings.togglerClassName = "tglBtn";
		}		
		if (typeof(settings.maskContainer) !== "string") {
			settings.maskContainer = "cBox";
		}
		if (typeof(settings.itemsContainer) !== "string") {
			settings.itemsContainer = "refLine";
		}
		if (typeof(settings.scrollerContainer) !== "string") {
			settings.scrollerContainer = "cFoot";
		}
		if (typeof(settings.emptyClassName) !== "string") {
			settings.emptyClassName = "hScrollBarEmpty";
		}
		if (typeof(settings.nthClassName) !== "string") {
			settings.nthClassName = "colLast";
		}
		if (typeof(settings.pagerNavigationClassName) !== "string") {
			settings.pagerNavigationClassName = "pageCounter";
		}
		if (typeof(settings.gridViewModeClassName) !== "string") {
			settings.gridViewModeClassName = "cToggleView";
		}
		if (isNaN(settings.minScrollBarWidth)) {
			settings.minScrollBarWidth = 33;
		}
	};

	showPage = function($content, $items, $footer, itemsPerPage, page) {
		var startIdx = (page-1)*itemsPerPage,
			endIdx = page*itemsPerPage-1,
			$emptyItem, $item, nbVisible = 0,
			hasColClassName = false,
			i, col;

		// clean empty items
		$content.children(".emptyJs").remove();

		$items.each(function(idx) {
			$item = $(this);
			if (idx >= startIdx && idx <= endIdx) {
				$item.addClass("scrollerGridViewShowJs").show();
				nbVisible++;
			} else {
				$item.addClass("scrollerGridViewHideJs").hide();				
			}
			if ($item.get(0).className.indexOf("col") !== -1) {
				hasColClassName = true;	
			}
		});
		

		if (hasColClassName) {
			$emptyItem = $($items[0]).clone();
				
			if (nbVisible < itemsPerPage) {
				$emptyItem.removeAttr("style").removeClass("scrollerGridViewShowJs").removeClass("scrollerGridViewHideJs").addClass("emptyJs").find(".unit:first").empty().append('<div class="unitExtra"></div>');
			
				for (i=1;i<(itemsPerPage-nbVisible);i++) {
					$content.append($emptyItem.clone());	
				}
			}

			col = parseInt($emptyItem.get(0).className.split("col")[1].split(" ")[0],10)-1;

			if ($.isFunction($.setClassToNthPosition)) {
				$.setClassToNthPosition($content.children(":visible:not(.hide)"), col, settings.nthClassName);
			}
		}
	};

	generateNavigationPager = function($widget) {
		var col = 3, row = 3,
			totalItems, itemsPerPage, nbPages,
			html = "", page,
			active = " class='active'",
			first = " class='first'",
			last = " class='last'",
			$items, $page, $footer, $content;

		$footer = $widget.find("."+settings.scrollerContainer);
		$footer.find("."+settings.pagerNavigationClassName).remove();

		$content = $(".scrollerContentJs", $widget);
		if ($content.length) {		
			$items = $content.children(":visible:not(.hide)");
			totalItems = $items.length;
			
			$items.each(function(idx) {
				if ($(this).hasClass(settings.nthClassName)) {
					col = idx+1;
					return false;	
				}
			});
			
			itemsPerPage = col*row;
			
			if (totalItems > itemsPerPage) {			
				nbPages = Math.ceil(totalItems/itemsPerPage);
	
				if (nbPages > 1) {
					html = "<div class='"+settings.pagerNavigationClassName+"'>";
					html += "<ul>\n";
					
					for (page=0;page<nbPages;page++) {
						if (page>0) { 
							active = "";
							first = "";						
						}
						if (page === nbPages-1) {
							first = last;	
						}
						html += "<li"+active+"><a"+first+" href='#'>";
						html += page+1;					
						html += "<span></span></a></li>\n";
					}
					html += "</ul>\n";
					html += "</div>";
					
					$page = $(html);
					$footer.append($page);
	
					// initial show
					showPage($content, $items, $footer, itemsPerPage, 1);
					
					$widget.find("."+settings.pagerNavigationClassName+" a").each(function(idx) {
						$(this).click(function() {
							$widget.find("."+settings.pagerNavigationClassName+" a").each(function(curIdx) {
								if (curIdx === idx) {
									$(this).parent().addClass("active");
								} else {
									$(this).parent().removeClass("active");
								}
							});
							showPage($content, $items, $footer, itemsPerPage, idx+1);
							return false;					 
						});
					});
				}
			}
		}
	};

	return this.each(function(idx){
		var $mask = $(this),
			maskWidth = $mask.innerWidth(),
			enableScroll, beenInitialized,
			$contents, $content, $contentVisible,
			contentItemWidth, margins, $contentChild,
			gridColMargin, contentWidth, childWidth,
			distanceToScroll, distanceToScrollRatio, $child, isVisible,
			$scroller, $scrollBar, $linkRewind, $linkForward,
			scrollBarWidget, scrollBarMinWidth,
			start, end, scrollBarWith,
			move, navigateStep, remainingStep,
			$handle, ratioBase, hundredPourcentGap,
			html, $tglBtn, $cToggle, displayText,
			widgetClassName = $.getJsClassName($mask),
			$cFoot = $mask.find("."+settings.scrollerContainer);
			
		// Loading problem detection
		if (maskWidth === 0) {
			// When maskWidth = 0, it means that the element is there but
			// for some reason is not fully DOM loaded and therefore accessing
			// computedStyle will not work properly	
			/*global window, setTimeout */
			window.scrollerId = setTimeout(function() {
				$mask.scroller({
					fillSpace: settings.fillSpace,
					fillSpacePaddingRight: settings.fillSpacePaddingRight,
					showNavigation: settings.showNavigation,
					speed: settings.speed,
					toggle: settings.toggle,
					toggleTitle: settings.toggleTitle,
					maskContainer: settings.maskContainer,
					itemsContainer: settings.itemsContainer,
					scrollerContainer: settings.scrollerContainer
				});
			}, 10);
		}
		
		if (window.scrollerId) { 
			/*global clearTimeout */
			clearTimeout(window.scrollerId); 
		}
		
		enableScroll = false;
		beenInitialized = false;
		
		//validateParams
		if (idx ===0) { 
			validateParams();
			
			if ($mask.hasClass("scrollerInitializedJs")) {
				beenInitialized = true;	
			}			
		}

		$contents = $mask.find("."+settings.itemsContainer);

		// Reset the scroller
		$mask.removeClass(settings.gridViewModeClassName).removeClass(widgetClassName).find(".emptyJs").each(function() {
			$(this).remove();																											  
		});
		
		if (beenInitialized) {
			$mask.removeClass(settings.emptyClassName);
			
			$contents.each(function() {
				$content = $(this);
				isVisible = $content.is(":visible");
				displayText = "block";
					
				if (!isVisible) { displayText = "none";	}
				
				$content.removeAttr("style").css("display", displayText);
			});
		}

		if (!$contentVisible) {
			$contentVisible = $mask.find("."+settings.itemsContainer+":visible:last");
		}

		// content must be visible
		$content = $contentVisible;
		if (settings.itemsContainer.indexOf("#") !== -1) {
			$content = $(settings.itemsContainer);	
		}

		if ($content.length) {
			$.scroller.resetNavigation($content);
			
			// plugin flags
			$content.addClass("scrollerContentJs");
			$mask.addClass("scrollerInitializedJs");
			
			// load images
			if ($.isFunction($.loadImages)) { 
				$.loadImages($content.find("img")); 
			}
			
			$contentChild = $content.children(":visible:not(.hide)");
			gridColMargin = parseInt($content.children(":last").css("margin-right"),10);
			contentWidth = 0;
			childWidth = 0;
				
			if ($contentChild.length) {
				childWidth = $($contentChild[0]).outerWidth();
				if (childWidth === 0) {
					childWidth = parseInt($($contentChild[0]).css("width"),10);
				}
			}
			if ((childWidth*$contentChild.length) > maskWidth) {
				enableScroll = true;

				// Add JsClassName
				if (widgetClassName!=="") { $mask.addClass(widgetClassName); }
				
				// Compute total content width
				$contentChild.each(function() {
					$child = $(this);
					childWidth = $child.outerWidth();
						
					if (childWidth === 0) {
						childWidth = parseInt($child.css("width"),10);
					} 
					margins = parseInt($child.css("marginLeft"),10) + parseInt($child.css("marginRight"),10);
					contentItemWidth = margins + childWidth;
					contentWidth += contentItemWidth;
				});
				$content.width(contentWidth);
		
				// slider needs to be initialize here in order
				// to generate the ui-handle.  After ui-handle generated,
				// we need to compute its start and end
				distanceToScroll = contentWidth-maskWidth-gridColMargin;
				if (distanceToScroll>0) {
					// Delete previous scroller
					$scroller = $mask.find(".scroller");
					if ($scroller.length) { $scroller.remove(); }
					
					// Create scroller HTML markup
					/*global document */
					$scroller = $("<div class='scroller'></div>");
					$scrollBar = $("<div class='scrollBar'></div>");
					$linkRewind = $("<div class='scrollBarRewind scrollBarRewindInactive'></div>");
					$linkForward = $("<div class='scrollBarForward'></div>");
					
					if (settings.showNavigation) {
						$scroller.append($linkRewind).append($scrollBar).append($linkForward);
					} else {
						$scroller.append($scrollBar);
						$scroller.css("paddingLeft",0).css("paddingRight",0);
					}
					
					$cFoot.append($scroller).append("<div class='clearer'><\/div>");
					
					// Must set scrollbar width
					if (!settings.fillSpace) {
						$mask.find("."+settings.scrollerContainer).css("paddingRight", settings.fillSpacePaddingRight);
					} else {
						$mask.find("."+settings.scrollerContainer).removeAttr("style");						
					}
					scrollBarWidget = $scroller.width();
					if (scrollBarWidget === 0) { 
						scrollBarWidget = "100%";
						$scrollBar.width(scrollBarWidget);
						scrollBarWidget = maskWidth;
					} else {
						$scrollBar.width(scrollBarWidget);	
					}
					
					
					// Compute handle / scrollBar Witdh
					// Slider component initialization
					$scrollBar.slider({							  
						value: start,
						slide: function(event, ui) {
							move = (distanceToScroll * (ui.value - start)) / remainingStep;
							
							$(this).find(".ui-slider-handle:first").addClass("scrollBarDrag");
		
							if (ui.value >= start && ui.value <= end) {
								$content.stop().css("left", -move+"px");
								$linkForward.removeClass("scrollBarForwardInactive");
								$linkRewind.removeClass("scrollBarRewindInactive");							
							} else if (ui.value < start) {
								$content.stop().css("left", "0px");
								$(this).slider("value",start);
								
								$linkForward.removeClass("scrollBarForwardInactive");									
								$linkRewind.addClass("scrollBarRewindInactive");
								return false;
							} else if (ui.value >= end) {
								$content.stop().css("left", -distanceToScroll+"px");	
								$(this).slider("value",end);
		
								$linkForward.addClass("scrollBarForwardInactive");
								$linkRewind.removeClass("scrollBarRewindInactive");
								return false;
							}else {
								return false;								
							}
						},
						stop: function() {
							$(this).find(".ui-slider-handle:first").removeClass("scrollBarDrag");
						}
					});
					
					// After widget initialization
					navigateStep = Math.ceil(maskWidth/contentItemWidth)*contentItemWidth;
					
					$scrollBar.find("a").html("<span></span>");
					
					$linkRewind.click(function() {
						var curPosition = parseInt($content.css("left"),10);
						if ((distanceToScroll-Math.abs(curPosition)+navigateStep) < distanceToScroll) {
							curPosition += navigateStep;
							$content.stop().animate({ "left": curPosition+"px"}, settings.speed);
							$(this).removeClass("scrollBarRewindInactive");
							$scrollBar.slider("value",parseInt(((Math.abs(curPosition)*remainingStep)+(distanceToScroll*start))/distanceToScroll,10));
						} else {
							$content.stop().animate({left :"0px"}, settings.speed);
							$scrollBar.slider("value", start);						
							$(this).addClass("scrollBarRewindInactive");
						}
						$linkForward.removeClass("scrollBarForwardInactive");						
						return false;																   
					});
		
					$linkForward.click(function() {
						var curPosition = parseInt($content.css("left"),10),
							ending = end;
							
						if (isNaN(curPosition)) { curPosition = 0;}
						if (Math.abs(curPosition)+navigateStep > distanceToScroll) {
							$(this).addClass("scrollBarForwardInactive");
							curPosition = -distanceToScroll;
						} else {
							$(this).removeClass("scrollBarForwardInactive");
							curPosition -= navigateStep;
							ending = parseInt(((Math.abs(curPosition)*remainingStep)+(distanceToScroll*start))/distanceToScroll,10);
						}
						$linkRewind.removeClass("scrollBarRewindInactive");						
						$content.stop().animate({left : curPosition+"px"}, settings.speed);
						$scrollBar.slider("value",ending);
						return false;
					});
		
					
					// Append extra markup to scrollBar
					$scrollBar.append("<span></span>");
		
					// Compute handle start / end / scrollbar-handle with
					$handle = $mask.find(".ui-slider-handle");				
					if ($handle.length) {
						distanceToScrollRatio = (distanceToScroll/contentWidth)*100;
						scrollBarWith = parseInt((Math.abs(distanceToScrollRatio-100)/100)*maskWidth,10);

						if (!settings.fillSpace) {							
							scrollBarWith -= settings.fillSpacePaddingRight/2;
						}
						
						// ScrollBar width size protection e.g scrollBar must have a minimum size in order
						// to be usable by the user
						if (scrollBarWith>scrollBarWidget) {
							scrollBarWith = scrollBarWidget-Math.ceil((distanceToScrollRatio/100)*scrollBarWidget);
							if (scrollBarWith>scrollBarWidget) {
								scrollBarWith = scrollBarWidget/2;
							} 
						} else {
							scrollBarMinWidth = Math.ceil((settings.minScrollBarWidth/100)*scrollBarWidget);
							if (scrollBarWith < scrollBarMinWidth) {
								scrollBarWith = scrollBarMinWidth;
							}
						}
						
						ratioBase = (scrollBarWith/scrollBarWidget)/2;
						start = Math.round(ratioBase*Math.pow(10,3))/Math.pow(10,3)*100;
						end = ((maskWidth-scrollBarWith)/maskWidth)*100;
						end += start;
						
						hundredPourcentGap = (100)-start-end;
						end += hundredPourcentGap;
						
						remainingStep = end-start;
						
						//  add margin negative in order to compensate -move
						$handle.css("marginLeft", -parseInt(scrollBarWith,10)/2+"px").width(scrollBarWith);
					}
					// Push ui-handle to the left to compensate margin negative
					$handle.css("left", start+"%");
				}
			} else {
				$mask.addClass(settings.emptyClassName).removeClass(widgetClassName);
				$cFoot.find(".scroller").remove();
			}
		}
		
		if (!settings.fillSpace) {
			// Toggle layout (scroll / grid)
			if (settings.toggle && enableScroll) {
				// Create HTML markup for fillSpace
				html = "";
				html += "<div class='tglBtn'>\n";
				html += "	<a href='#' title='"+decodeURIComponent(settings.toggleTitle).replace("'","`").replace("'","`")+"'>"+decodeURIComponent(settings.toggleTitle).replace("'","`").replace("'","`")+"<\/a>\n";
				html += "<\/div>\n";
	
				$tglBtn = $(this).find(".tglBtn");
				
				// Remove previous toggles
				if ($tglBtn.length) { $tglBtn.remove(); } 
				
				$mask.find("."+settings.scrollerContainer).append(html);
				$tglBtn = $(this).find(".tglBtn");
				
				// Initialize toggleViews with scroll vs ListView
				$tglBtn.each(function() {
					$(this).unbind("click").click(function() {
						$cToggle = $(this).parents("."+settings.maskContainer+":first");
						$content = $cToggle.find("."+settings.itemsContainer+":visible:first");
						$content.stop();

						// cleanup previous show/hide state
						$.scroller.resetNavigation($content);
						
						if ($cToggle.hasClass(widgetClassName)) { // GridView
							$cToggle.each(function(){
								$(this).removeClass(widgetClassName).addClass(settings.gridViewModeClassName);
								
								$content = $(this).find("."+settings.itemsContainer+":visible");						
								$content.removeAttr("style").show();
								$(this).find(".scroller").remove();
	
								//Trigger hasLayout for IE6
								if ($.isFunction($.hasLayout)) {
									$.hasLayout($content);
								}
								
								generateNavigationPager($cToggle);
								
								return false;						
							});					
						} else { // Scroller View
							$cToggle.addClass(widgetClassName).removeClass(settings.gridViewModeClassName);

							$cToggle.scroller({
								fillSpace: settings.fillSpace,
								fillSpacePaddingRight: settings.fillSpacePaddingRight,
								showNavigation: settings.showNavigation,
								speed: settings.speed,
								toggle: settings.toggle,
								toggleTitle: settings.toggleTitle,
								maskContainer: settings.maskContainer,
								itemsContainer: settings.itemsContainer,
								scrollerContainer: settings.scrollerContainer
							});
							//Trigger hasLayout for IE6
							if ($.isFunction($.hasLayout)) {
								$.hasLayout($content);
							}

							// scroll animation
							if ($.isFunction(jQuery.scrollToElement)) {
								$.scrollToElement($cToggle);	
							}
						}
						
						// equalize units
						if ($.isFunction(jQuery.fn.equalize)) {
							// TODO: find a way to not hardcode value here
							$(this).parents("."+widgetClassName+"Js:first").equalize({similarItem:"unit"});
						}
					});
				});
			} else {
				$mask.find("."+settings.togglerClassName+", ."+settings.pagerNavigationClassName).remove();
			}
		} else {
			$mask.find("."+settings.togglerClassName+", ."+settings.pagerNavigationClassName).remove();
		}
		// finally we update items count if applicable
		$.scroller.updateItemsCount($mask, "h2");

		if ($.isFunction($.pageRender)) {
			if ($mask.length) {
				if ($content) {
					// equalize units
					if ($.isFunction(jQuery.fn.equalize)) {
						// TODO: find a way to not hardcode value here
						$content.equalize({similarItem:"unit"});
					}
				}
				$.pageRender($mask, "scroller");
			}
		}
	});
};
jQuery.scroller = {
	count: function(maskContainer) {
		var	result = 0,
			$container = $(maskContainer),
			$content;
			
		if ($container.length) {
			$content = $(".scrollerContentJs", $container);
			if ($content.length) {
				return $content.children(":visible:not(.hide):not(.emptyJs)").length;	
			}
		}
		return result;
	},
	// cleanup previous scroller items show/hide state
	resetNavigation: function(content) {
		var $child, $content, removeInlineFnEnable = $.isFunction($.removeInlineCSSProp);
		$content = $(content);
		$content.children().each(function() {
			if (this.className.indexOf("scrollerGridView") !== -1) {
				$child = $(this);
				$child.removeClass("scrollerGridViewShowJs").removeClass("scrollerGridViewHideJs");
				if (removeInlineFnEnable) {
					$.removeInlineCSSProp($child,"display");
				}
			}
		});		
	},	
	// update container listing title when having multiple scrollers and toggles
	updateItemsCount : function(scroller, titleHtmlTag) {
		var $scroller = $(scroller),
			$title = $(titleHtmlTag+":first", $scroller),
			text = $title.text(),
			textIdx = text.indexOf("("),
			label, newValue;
									 
		if (textIdx !== -1) {
			text = text.substr(0, textIdx);			   
		}
		label = " "+$.getText("items");
		newValue = this.count($scroller);
		
		if (newValue > 1) { label += "s"; }
		label = "("+newValue+label+")";
					
		text = text+" <span>"+label+"</span>";

		$title.html(text);
		/*global Cufon */
		if (typeof(Cufon) === "function") {
			Cufon.replace($title);
		}
	}
};
/***************************************************/
// plugin: equalize
//
/**********************************************************/
jQuery.fn.equalize = function(settings) {
	var defaults, validateParams, getExtraHeights, loadMedias;
	
	defaults = {
		similarItem: "unit",
		insideItems: ["bStick"],
		removePaddingsClassName: "stickyPict"
	};
	settings = $.extend(defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.similarItem) !== "string") {
			settings.similarItem = "unit";
		}
		if (typeof(settings.insideItems) !== "object") {
			settings.insideItems = ["bStick"];
		}
	};

	getExtraHeights = function($item) {
		var extraHeights = 0,
			arrExtras = $.makeArray(settings.insideItems);
			
		$.each(arrExtras, function(idx, value) {
			$item.find("."+value).each(function() {
				return (function($extraElement) {
					extraHeights += $extraElement.outerHeight(true);
				})($(this));
			});			
		});
		return parseInt(extraHeights,10);
	};
	
	loadMedias = function(itemImages) {
		if ($.isFunction($.loadImages)) {
			return (function(images) {
				$.loadImages(images);
			})(itemImages);
		} 
	};

	return this.each(function(idx){
		//validateParams
		if (idx ===0) { validateParams(); }
							  
		var currentTallest = 0,
			$items = $(this).find("."+settings.similarItem),
			itemH = 0,
			largerImageFound = false,
			$item, $img,
			imgH, contentH, arrExtras,
			currentFontSize, cssProp,
			$tmpElement, newHeight,
			isIE6 = $.isIE(6);			
			
		
		if ($items.length) {		
			loadMedias($("img",$items));
		
			$items.each(function(){
				$item = $(this);
				
				// remove any height styling
				$item.removeAttr("style").removeClass("eqImgSmallerJs").removeClass("eqImgLargerJs");
				
				itemH = $item.height()+getExtraHeights($item);
				
				$item.find("img").each(function() {
					$img = $(this);
					imgH = $img.outerHeight();
	
					// Most of the structure contains itemInfo otherwise
					// function will simply ignore itemInfo
					$item.find(".itemInfo").each(function() {
						contentH = $(this).outerHeight(true);								  
					});
						
					if ($img.css("float") !== "none") {
						if (imgH > contentH) {
							//To avoid any extra spacing, we take the diffence space
							//between larger image and content
							itemH -= (imgH-contentH);
							largerImageFound = true;
							$item.addClass("eqImgLargerJs");	
						} else {
							//Do nothing to unit because image is smaller than content.
							//So content will automatically flow in it's original flow stack
							$item.addClass("eqImgSmallerJs");
						}
					} else {
						// here we are probably in a position: absolute scenario
						if ($.isIE(6)) {
							if ($img.css("position").toLowerCase() === "absolute") {
								if (imgH > contentH) {
									itemH = imgH;
									itemH -= parseInt($item.css("paddingBottom"),10);
								} else {
									itemH = $item.outerHeight(true)+getExtraHeights($item);
									
									arrExtras = $.makeArray(settings.insideItems);
									$.each(arrExtras, function(idx, value) {
										// Each extra element we remove the extra height + the bottom value
										$item.find("."+value+":first").each(function() {
											return (function($extraElement) {
												itemH -= parseInt($extraElement.css("bottom"),10)*2;
											})($(this));
										});
														   
									});
								}
							}
						}
					}
				});
				
				if (itemH > currentTallest) { 
					currentTallest = itemH;
				}
			});
			
			if ($.isIE()) {
				$tmpElement = $("<span id='fontSizeChecker'>fontSize</span>");
				$tmpElement.css("fontSize", "1em");
				$("body").append($tmpElement);
				currentFontSize = $.getPixelValue($("#fontSizeChecker"),$("#fontSizeChecker").css("fontSize"));
				$tmpElement.remove();
			} else {
				currentFontSize = parseInt($("body").css("fontSize"),10);
			}
	
			newHeight = (currentTallest/currentFontSize);
			
			if (newHeight > 0)	{		
				cssProp = isIE6?'height':'min-height';
				$items.each(function() {
					$(this).css(cssProp,newHeight + ("em"));
				});
		
				if (largerImageFound) {
					currentTallest = 0;
					$items.each(function() {
						itemH = $(this).height();
						if (itemH > currentTallest) {
							currentTallest = itemH;
						}
					});
					newHeight = (currentTallest / currentFontSize) + ("em");
					cssProp = isIE6?'height':'min-height';
					$items.each(function() {
						$(this).css(cssProp,newHeight);
					});
				}
			}
		}
	});
};
/***************************************************/
// plugin: toggleShowHide
/**********************************************************/
jQuery.fn.toggleShowHide = function(settings) {
	var validateParams, bindClickEvent, runExternalProcess, elements = this;
	settings = $.extend(false, $.toggleShowHide.defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.slide) !== "boolean") {
			settings.slide = false;
		}		
	};

	bindClickEvent = function() {
		elements.live("click", function() {
			var $element = $(this),
				$content = [], contentId,
				href = $element.attr("href"),
				rev = $element.attr("rev"),
				isInPage = true;
			
			if (href) {
				if (href.substr(0,1) !== "#") {	
					if (rev) {
						isInPage = false;
						contentId = rev;
					} else if (href.indexOf("#") !== -1) {
						contentId = href.split("#")[1];
					} 
				} else {
					contentId = href.split("#")[1];
				}
				if (contentId && contentId !== "") {
					$content = $("#"+contentId);
				}
				
				if ($content.length) {
					if (!isInPage && !$.data($element.get(0),"loaded")) {
						$.ajaxLoader.show();
						$.ajax({
							url: href,
							success: function(data) {
								$.ajaxLoader.hide();									
								$content.html(data);
								// TODO: remove hardcoded value here
								$(".tglJs", $content).toggleShowHide();
								
								$.toggleShowHide.animateText($element, $content);
								$.data($element.get(0),"loaded",settings);
							},
							error: function() {
								$.ajaxLoader.hide();
								var defErrorText = "Error";
								if ($.isFunction($.getText)) {
									$content.html($.getText("error"));
								} else {
									$content.html(defErrorText);
								}
								$.data($element.get(0),"loaded",true);									
							}
						});
					} else {
						$.toggleShowHide.animateText($element, $content);
					}
					runExternalProcess($content);
				}
			}
			
			return false;
		});
		
		// Third-Party optional process
		runExternalProcess = function($content) {
			if ($.brad.external) {
				if ($.isFunction($.brad.external.tracker)) {
					if ($content.parents(".detailPanel:first").length) {
						$.brad.external.tracker({
							appName: "lp",
							data: {
								componentName: "PromotionDetails"
							}
						});
					}
				}
			}
		};
	};

	return this.each(function(idx){
		var $element = $(this),
			$content, widgetClassName,
			isInPage = true,
			href = $element.attr("href");

		// validateParams
		if (idx ===0) { validateParams(); }

		if (href) {
			if (href.substr(0,1) !== "#") { isInPage = false; }

			$content = $.toggleShowHide.getContent($element);

			if ($content.length) {
				widgetClassName = "";
				if ($.isFunction($.getJsClassName)) {
					widgetClassName = $.getJsClassName($element);
					$element.addClass(widgetClassName);
					
					// default state opened?closed
					if (!$element.hasClass(widgetClassName+"Open")) {
						$content.hide();
					} else if (!isInPage) {
						$.ajaxLoader.show();
						$.ajax({
							url: href,
							success: function(data) {
								$.ajaxLoader.hide();									
								$content.html(data);
								// TODO: remove hardcoded value here
								$(".tglJs", $content).toggleShowHide();
								
								$.data($element.get(0),"loaded",true);
							},
							error: function() {
								$.ajaxLoader.hide();
								var defErrorText = "Error";
								if ($.isFunction($.getText)) {
									$content.html($.getText("error"));
								} else {
									$content.html(defErrorText);
								}
								$.data($element.get(0),"loaded",true);									
							}
						});
					}
				}
				
				settings.widgetClassName = widgetClassName;
		
				// Toggle text handling
				if (!$.data($element.get(0),"settings")) {
					$element.attr("title", $element.text());
					if ($.toggleShowHide.toToggleText($element)) {
						$.toggleShowHide.toggleText(-1,$element);
						if ($element.hasClass(widgetClassName+"Open")){
							$.toggleShowHide.toggleText(1,$element); 
						}
					}
					$.data($element.get(0),"settings", settings);					
				}
				
				if (idx===0) { bindClickEvent(); }
			}
		}
	});
};
jQuery.toggleShowHide = {
	defaults : {
		slide: true
	},
	update: function(params) {
		var $link, settings, $content, defaults,
			goodIE = $.isIE(">8");
		
		if (typeof(params) === "object") {
			// defaults are there for security only
			defaults = {
				linkElement: [],
				ajax: false,
				inPage: true,
				text: false,				
				url: "",
				targetId: "",
				content: ""
			};
			
			params = $.extend(false,defaults,params);
			
			$link = $(params.linkElement);
			
			if ($link.length) {
				settings = $.data($link.get(0),"settings");				
				if (settings) {
					settings = $.extend(false,params,settings);
					$content = this.getContent($link);
					
					$.removeData($link.get(0),"loaded");
					
					if (settings.ajax) {
						$link.attr("rev", $content.attr("id"));
						$link.attr("href",settings.url);
					}else if (settings.inPage) {
						$link.attr("href","#"+settings.targetId);
					}

					if ($content.length) {
						if ((settings.slide && !$.isIE()) || (settings.slide && goodIE)) {
							$content.animate({opacity:0},100).slideUp(function() {
								$content.empty();												   
							});
						} else {
							$content.hide().empty();
						}
						if ($link.hasClass("tglActiveJs")) {
							$link.removeClass("tglActiveJs");
							if (settings.widgetClassName !== "") {
								$link.removeClass(settings.widgetClassName+"Open");
							}
						}
						this.toggleText(0,$link);						
						
						if (settings.text) {
							$content.html(settings.content);	
						}
					}
				}
			}
		}
	},
	getContent: function(linkElement) {
		var $link = $(linkElement),
			href = $link.attr("href"),
			rev =  $link.attr("rev"), contentId,
			$content = [];
			
		if ($link.length) {
			if (href) {
				if (href.substr(0,1) !== "#") {	
					if (rev) {
						contentId = rev;
					} else if (href.indexOf("#") !== -1) {
						contentId = href.split("#")[1];
					} 
				} else {
					contentId = href.split("#")[1];
				}
				if (contentId && contentId !== "") {
					$content = $("#"+contentId);
				}
			}
		}
		return $content;
	},
	toToggleText: function(element) { // find toggle text
		var $element = $(element),
			str = $element.attr("title"),
			rel = $element.attr("rel"),
			toggleTextFounded = false;
			
		if (str.indexOf(rel) !== -1) {
			toggleTextFounded = true;
		}
		return toggleTextFounded;
	},
	replaceText: function(searchText, newText, element) {
		var $element = $(element);
		$element.html($element.html().replace(searchText, newText));
	},
	toggleText: function(showState,element) {
		var $element = $(element),
			rel, originaltext,
			arrRel, text;
		
		if (this.toToggleText($element)) {
			rel = $element.attr("rel");
			originaltext = $element.attr("title");

			if (rel !== "") {
				if (rel.indexOf("/") !== 0) {
					arrRel = rel.split("/");
					
					if (arrRel.length) {
						switch(showState) {
							case -1: // initial state
								text = originaltext.replace(arrRel[1], arrRel[0]);
								text = text.replace(arrRel[0]+"/","");
								this.replaceText(originaltext, text, $element);
								break;
							case 0: // Show state
								
								text = originaltext.replace(arrRel[showState+1], arrRel[showState]);	
								text = text.replace(arrRel[showState]+"/","");
								this.replaceText($element.text(), text,  $element);
								$element.removeClass("tglActiveJs");
								break;
							case 1: // Hide state
								text = originaltext.replace(arrRel[showState-1], arrRel[showState]);	
								text = text.replace("/"+arrRel[showState],"");
								this.replaceText($element.text(), text,  $element);							
								$element.addClass("tglActiveJs");
								break;
						}
					}
				}
			}
		}
	},
	animateText: function($element, $content) {
		var widgetClassName = "",
			settings = $.data($element.get(0),"settings"),
			isIE = $.isIE(), goodIE = $.isIE(">8");
		
		if (!settings) { 
			settings = this.defaults;
			$.data($element.get(0),"settings", settings);
		}
		
		if ($.isFunction($.getJsClassName)) {
			widgetClassName = $.getJsClassName($element);
			$element.addClass(widgetClassName);
			
			// default state opened?closed
			if (!$element.hasClass(widgetClassName+"Open")) {
				$content.hide();
			}			
		}

		if (widgetClassName !== "") {
			$element.toggleClass(widgetClassName+"Open");
		}
		
		if (!$content.is(":visible")) {
			if ((settings.slide && !$.isIE()) || (settings.slide && goodIE)) {
				$content.css("opacity",0).slideDown(function() {
					$content.animate({opacity:1},"fast");
				});
			} else {
				$content.css("opacity",1).show();
				if (isIE) { 
					$.removeInlineCSSProp($content, "filter");
					$.hasLayout($content);					
				}
			}
		} else {
			if ((settings.slide && !$.isIE()) || (settings.slide && goodIE)) {
				$content.animate({opacity:0},100).slideUp();
			} else {			
				$content.hide();
				if (isIE) { 
					$.removeInlineCSSProp($content, "filter");					
					$.hasLayout($content);
				}
			}
		}
		$.hasLayout($content);

		this.toggleText($element.hasClass("tglActiveJs")?0:1,$element);
	}
};
/***************************************************/
// plugin: formatPrice
/**********************************************************/
jQuery.fn.formatPrice = function(settings) {
	var defaults, validateParams;
	
	defaults = {
		htmlTag: "span",
		className: "superscript"
	};
	settings = $.extend(defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.htmlTag) !== "string") {
			settings.htmlTag = "span";
		}
		if (typeof(settings.className) !== "string") {
			settings.className = "superscript";
		}
	};

	return this.each(function(idx){
		var $element = $(this),
			str, dollarPosition,
			cents, centsPosition, i,
			dollarHasBeenFormatted;
		
		//validateParams
		if (idx ===0) { validateParams(); }
		
		str = $.trim($element.text());
		
		dollarPosition = str.indexOf("$");
		if (dollarPosition !== -1) {
			// Detect FR/EN format
			if (dollarPosition === 0) {
				// EN format e.g $23.95
				for	(i=0;i<str.length;i++) {
					if (str.substr(dollarPosition+1, i).indexOf(".") !== -1) {
						cents = $.trim(str.substr(dollarPosition+1+i,2));
						if (!isNaN(cents) && (cents.length>0)) {
							cents = str.substr(dollarPosition+i,3);
							// Replace cents with HTML markup
							centsPosition = $element.html().indexOf(cents);
							if (!isNaN($element.html().substr(centsPosition-1, 1))) {
								$element.html($element.html().replace(cents,"<"+settings.htmlTag+" class='"+settings.className+"'>"+cents+"</"+settings.htmlTag+">"));
							}
						}
						break;
					}
				}
			} else {
				// FR 
				// format 1) 23,95 $  (with space between cents and $)				
				// format 2) 23.95$ / 23,95$
				
				// Format 1)
				cents = str.substr(dollarPosition-4, 3);
				if (cents.indexOf(",") === 0) {
					// Replace cents with HTML markup
					centsPosition = $element.html().indexOf(cents);
					if (!isNaN($element.html().substr(centsPosition-1, 1))) {
						$element.html($element.html().replace(cents,"<"+settings.htmlTag+" class='"+settings.className+"'>"+cents+"</"+settings.htmlTag+">"));
					}
				} else {
					// Format 2)
					cents = str.substr(dollarPosition-3, 3);
					if (cents.indexOf(".") !== -1 || cents.indexOf(",") !== -1) {
						// Replace cents with HTML markup
						centsPosition = $element.html().indexOf(cents);
						if (!isNaN($element.html().substr(centsPosition-1, 1))) {
							$element.html($element.html().replace(cents,"<"+settings.htmlTag+" class='"+settings.className+"'>"+cents+"</"+settings.htmlTag+">"));
						}
					}
				}
			}
			// Replace $ sign with HTML markup
			dollarHasBeenFormatted = false;
			$element.find("."+settings.className).each(function() {
				if ($(this).text()==="$") {
					dollarHasBeenFormatted = true;
					return false;
				}
			});
			
			if (!dollarHasBeenFormatted) {
				$element.html($element.html().replace("$","<"+settings.htmlTag+" class='"+settings.className+"'>$</"+settings.htmlTag+">"));
			}
		} else {
			centsPosition = str.search(new RegExp("\u00A2"));
			if (centsPosition !== -1) {
				cents = str.substr(centsPosition-1, 1);

				// Replace ?sign with HTML markup
				dollarHasBeenFormatted = false;
				$element.find("."+settings.className).each(function() {
					if ($.trim($(this).html())==="\u00A2") {
						dollarHasBeenFormatted = true;
						return false;
					}
				});
				
				if (!dollarHasBeenFormatted) {					
					$element.html($element.html().replace("\u00A2","<"+settings.htmlTag+" class='"+settings.className+"'>&#162;</"+settings.htmlTag+">"));
				}
			}
		}
	});
};
/***************************************************/
// plugin: toRemove TODO: add cookie capabilities
/**********************************************************/
jQuery.fn.toRemove = function(settings) {
	settings = $.extend(false, $.toRemove.defaults, settings);

	// Validate Params
	var validateParams = function() {
		if (typeof(settings.fade) !== "boolean") {
			settings.fade = false;
		}
		if (isNaN(settings.speed)) {
			settings.speed = 500;
		}			
		if (typeof(settings.cookie) !== "boolean") {
			settings.cookie = false;
		}
		if (typeof(settings.cookieName) !== "string") {
			settings.cookieName = "random_unique_QWERTY";
		}
		if (isNaN(settings.cookieExpire)) {
			settings.cookieExpire = 30;
		}

	};

	return this.each(function(idx){
		//validateParams
		if (idx ===0) { 
			validateParams(); 

			this.live("click", function() {
				$.toRemove.remove($(this), settings);
				return false;
			});
		}
	});
};
jQuery.toRemove = {
	defaults: {
		fade: true,
		speed: 500,
		cookie: false,
		cookieName: "random_unique_QWERTY",
		cookieExpire: 30
	},
	remove: function(element, settings) {
		if (typeof(settings) === "undefined") {
			settings = this.defaults;	
		}
		
		var $element = $(element),
			linkUrl, contentId,
			$content, isIE = false;			
			
		if ($element.attr("href")) {
			linkUrl = $element.attr("href");
			if (linkUrl.length > 1 && linkUrl.indexOf("#") !== -1) {
				contentId = linkUrl.split("#")[1];
	
				$content = $("#"+contentId);
				if (settings.fade) {
					if ($.isFunction($.isIE)) {
						isIE = $.isIE("<9");
					}
					if (!isIE) {
						$content.animate({opacity:0},function() { 
							$(this).slideUp(settings.speed, function() {
								$(this).hide();						 
							}); 
						});
					} else {
						// opacity problem with IE < 9
						$content.fadeOut(settings.speed);
					}
				} else {
					$content.hide();
				}
			}
		}	
	}
};
/***************************************************/
// plugin: toShow
/**********************************************************/
jQuery.fn.toShow = function(settings) {
	var defaults, validateParams;
	
	defaults = {
		fade: true,
		speed: 500
	};
	settings = $.extend(defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.fade) !== "boolean") {
			settings.fade = false;
		}
		if (isNaN(settings.speed)) {
			settings.speed = 500;
		}			
	};

	return this.each(function(idx){
		var $element = $(this),
			linkUrl, contentId;
		
		if ($element.attr("href")) {
			linkUrl = $(this).attr("href");
			if (linkUrl.length > 1 && linkUrl.indexOf("#") !== -1) {
				contentId = linkUrl.split("#")[1];

				//validateParams
				if (idx ===0) { validateParams(); }
	
				$element.unbind("click").click(function() {
					var $content = $("#"+contentId);
					if (settings.fade) {
						$content.fadeIn();
					} else {
						$content.show();
					}
					return false;						
				});
			}
		}
	});
};
/***************************************************/
// plugin: toolTip
/**********************************************************/
jQuery.fn.toolTip = function(settings) {
	var defaults, isHTML, validateParams, setPosition;
	
	defaults = {
		fade: true,
		follow: true,
		enableClick: true,
		unToolTip: false,
		offSetX: 0,
		offSetY: 15,
		minWidth: 200,	
		maxWidth: 300,
		containerId: "brad-toolTip",
		arrowId: "toolTipArrow"
	};
	settings = $.extend(defaults, settings);

	isHTML = false;

	// Validate Params
	validateParams = function() {
		if (typeof(settings.fade) !== "boolean") {
			settings.fade = true;
		}
		if (typeof(settings.follow) !== "boolean") {
			settings.follow = true;
		}
		if (typeof(settings.enableClick) !== "boolean") {
			settings.enableClick = true;
		}
		if (typeof(settings.unToolTip) !== "boolean") {
			settings.unToolTip = false;
		}
		if (isNaN(settings.offSetX)) {
			settings.offSetX = 0;
		}
		if (isNaN(settings.offSetY)) {
			settings.offSetY = 15;
		}
		if (isNaN(settings.minWidth)) {
			settings.minWidth = 200;
		}
		if (isNaN(settings.maxWidth)) {
			settings.maxWidth = 300;
		}
		if (typeof(settings.containerId) !== "string") {
			settings.containerId = "toolTip";
		}
		if (typeof(settings.arrowId) !== "string") {
			settings.arrowId = "toolTipArrow";
		}			
	};

	// Position the toolTip
	setPosition = function(e) {
		var top, left, arrowLeft,
			$toolTip = $("#"+settings.containerId),
			$arrow = $("#"+settings.arrowId),
			toolTipH = $toolTip.outerHeight(),
			toolTipW = $toolTip.outerWidth(),
			arrowH = parseInt($arrow.css("height"),10),
			arrowW = parseInt($arrow.css("width"),10),
			arrowPositionRatio = toolTipW/4,
			winW = $(window).width(),
			toolTipPosition, reverseLeft;
		
		if ($toolTip.length) {
			top = e.pageY-settings.offSetY-toolTipH-arrowH;
			left = e.pageX - arrowPositionRatio;
			arrowLeft = arrowPositionRatio-(arrowW/2);

			// Pre-compute ToolTip position including width etc...
			toolTipPosition = left + toolTipW;

			if (toolTipPosition > winW) {
				// We know the toolTip will bust the window
				// now we will prevent it
					
				// reverse left position of toolTip to the right
				reverseLeft = left-toolTipW*0.75+arrowPositionRatio-(arrowW/2)-8;
				$toolTip.css("top",top+"px").css("left",reverseLeft+"px");
				
				if ($arrow.length) {
					$arrow.css("left",arrowPositionRatio*3+10+"px");
				}
			} else {
				$toolTip.css("top",top+"px").css("left",left+"px");
				
				if ($arrow.length) {
					$arrow.css("left",arrowLeft+"px");													
				}
			}
		}
	};

	return this.each(function(idx){
		var $element = $(this),
			txt, contentId, $content,
			$toolTip, toolTipTitle, html, $arrow;
			
		//validateParams
		if (idx ===0) { validateParams(); }
		
		if (!settings.unToolTip) {
			if (!$.data($element.get(0),"initialized")) {
				if (!settings.enableClick) {
					// preventDefault action
					$element.click(function() {
						return false;
					});
				}
				
				// Set hover action
				$element.mouseover(function(e){
					// Get Text
					$.data($element.get(0),"bradToolTip", this.title);
		
					// Trying to detect if toolTip content's from title or HTML
					contentId = "";
					try {
						contentId = $(this).attr("href").split("#")[1];
					} catch(ex) {}
					
					if (contentId !== "") {
						isHTML = true;
						$content = $("#"+contentId);
						if ($content.length) {
							txt = $content.html();
						}
					}
					if (!txt || txt === "" || typeof(txt) == "undefined") {
						txt = this.title;
						isHTML = false;
					}
					
					// Create ToolTip if only text exists
					if (txt !== "" && txt) {
						txt = $.trim(txt);
						if (txt !== "") { 
							// Temporary remove title because we don't want to show the browser's
							// native toolTip behavior
							this.title = "";
						
							// hide previous tooltip
							$("#"+settings.containerId).remove();
							
							$toolTip = $("<div id='"+settings.containerId+"' class='toolTip'></div>");
							
							html = "";
							html += "	<div class='toolTipBordRight'>\n";
							html += "		<div class='toolTipBordLeft'>\n";
							html += "			<div class='lining'>\n";
							html += txt;
							html += "			<\/div>\n";
							html += "		<\/div>\n";
							html += "	<\/div>\n";
							html += "	<div class='toolTipTopRight'><div class='toolTipTopLeft'><\/div><\/div>\n";
							html += "	<div class='toolTipBottomRight'>\n";
							html += "		<div class='toolTipBottomLeft'>\n";
							html += "		<\/div>\n";
							html += "	<\/div>\n";
							html += "	<div id='"+settings.arrowId+"' class='toolTipArrow'><\/div>\n";
		
							$toolTip.append(html);
							$toolTip.appendTo("body");
							
							$arrow = $("#"+settings.arrowId);
				
							// set minWidth/maxWidth if applicable
							if ($toolTip.width() > settings.maxWidth) {
								$toolTip.css("width",settings.maxWidth + "px");
							} else if ($toolTip.width() < settings.minWidth) {
								$toolTip.css("width",settings.minWidth + "px");							
							}
		
							// IE PNG check
							if ($.isIE("<9")) {
								if ($toolTip.css("backgroundImage").indexOf(".png") !== -1 || $arrow.css("backgroundImage").indexOf(".png") !== -1) {
									settings.fade = false;
								}
							}	
				
							// Position toolTip
							setPosition(e);
							
							// Show toolTip
							if (settings.fade) {
								$toolTip.stop().fadeIn("fast");
							} else {
								$toolTip.show();
							}
						}
					}
				}).mouseout(function(){
					toolTipTitle = $.data($element.get(0),"bradToolTip");
					if (toolTipTitle) {
						this.title = toolTipTitle;
						//this.title = this.tempTitle;
					}
					var $toolTip = $("#"+settings.containerId);
		
					if (settings.fade) {
						$toolTip.stop().fadeOut("fast", function() {
							$(this).remove();								  
						});
					} else {
						$toolTip.remove();
					}
				});
				if (settings.follow) {
					$element.mousemove(function(e){
						// Position toolTip
						setPosition(e);
					});
				}
				$.data($element.get(0),"initialized", true);
			}
		} else {
			// UnToolTip
			$element.unbind("mouseover").unbind("mouseout");
			$.removeData($element.get(0),"toolTipInitialized");
		}
	});
};
/***************************************************/
// plugin: Carousel
/**********************************************************/
jQuery.fn.carousel = function(settings) {
	var defaults, timerId, validateParams, loadMedias, 
		setDimension, show, playShow, play;
	
	defaults = {
		autoPlay: false,
		timer: 5, // in seconds
		slide: false,
		speed: 300,
		navInside: false,
		navCenter: true,
		navShow: true,
		navContainer: "carouselNav",
		mediaContainer: "carouselMedia",
		activeClassName: "active"
	};
	settings = $.extend(defaults, settings);

	timerId = 0;

	// Validate Params
	validateParams = function() {
		if (typeof(settings.autoPlay) !== "boolean") {
			settings.autoPlay = false;
		}
		if (isNaN(settings.timer)) {
			settings.timer = 5;
		}
		if (typeof(settings.slide) !== "boolean") {
			settings.slide = false;
		}
		if (isNaN(settings.speed)) {
			settings.speed = 300;
		}
		if (typeof(settings.navInside) !== "boolean") {
			settings.navInside = false;
		}
		if (typeof(settings.navCenter) !== "boolean") {
			settings.navCenter = true;
		}
		if (typeof(settings.navShow) !== "boolean") {
			settings.navShow = true;
		}
		if (typeof(settings.navContainer) !== "string") {
			settings.navContainer = "carouselNav";
		}
		if (typeof(settings.mediaContainer) !== "string") {
			settings.mediaContainer = "carouselMedia";
		}
		if (typeof(settings.activeClassName) !== "string") {
			settings.activeClassName = "active";
		}
	};

	// set images width/height by loading the images
	loadMedias = function($carouselImages) {
		if ($.isFunction($.loadImages)) { 
			$carouselImages.each(function() {
				var $image = $(this),
					$link, toHide;
					
				if ($image.attr("id") === "") {
					if (document.getElementById($image.parent().attr("id")).nodeName === "A") {
						$link = $($image.parent());
						toHide = false;
						
						if (!$link.is(":visible")) {
							toHide = true;
							$link.show();
						}
						return function() {
							$.loadImages($("img", $link));
							if (toHide) { $link.hide(); }
						};
					}
				} else {
					return function() { $.loadImages($image); };
				}			
			});
		}
	};

	// set carousel dimension by tallest and widest image
	setDimension = function($element) {
		var tallestH = 0,
			tallestW = 0,
			totalImgW = 0,
			dimension = {
				height: 0,
				width: 0
			}, 
			validData = false,		
			$carouselImages = $element.find("."+settings.mediaContainer+" img"),
			zIndex, $img, imgH, imgW, killOutLine,
			$nav;

		// load images
		loadMedias($carouselImages);
		
		zIndex = 66666;
		
		$carouselImages.each(function(i) {
			$img = $(this);
			imgH = $img.outerHeight();
			imgW = $img.outerWidth();			
			
			// functionality check
			if (imgH === 0) {
				// somethings wrong !!!
				return false;
			} else {
				validData = true;	
			}
			
			if (imgH > tallestH) {
				tallestH = imgH;
			}
			
			if (imgW > tallestW) {
				tallestW = imgW;
			}
			dimension.height = tallestH;
			dimension.width = tallestW;
			
			totalImgW += imgW;

			if (!$img.attr("id")) {
				if (document.getElementById($img.parent().attr("id")).nodeName === "A") {
					$img = $($img.parent());
				}
			}
			
			// always show first
			if (i === 0) { $img.show(); }
			
			if (i === 0 || !settings.slide) {
				$img.css("left", 0);
				if (i > 0 && !settings.slide) {
					$img.hide();	
				} 
				if (!settings.slide) {
					$img.css("position","absolute");
				}
			} else {
				$img.css("left", totalImgW-imgW+"px").css("float", "left");
			}
		});

		// functionality check
		if (!validData) {
			// Somethings wrong exit function
			return false;	
		} else {
			// Everything seems to be OK! Now set Mask width
			if (dimension.width) {
				$element.width(dimension.width);	
			}
			
			// Set the media container width
			$element.find("."+settings.mediaContainer).each(function() {
				if (settings.slide) {
					$(this).width(totalImgW);
				} else {
					$(this).width(dimension.width);
				}
			});
			
			killOutLine = false;
			if ($.isFunction($().outLineKiller)) {
				killOutLine = true;
			}
			
			// position navigation
			$element.find("."+settings.navContainer).each(function() {
				$nav = $(this);
				if (settings.navShow) {
					if (settings.navCenter) {
						$nav.css("left", (dimension.width-$nav.width())/2+"px");
					}
					if (killOutLine) {
						$("a",$nav).outLineKiller();
					}
					
					if (dimension.height) {
						if (settings.navInside) {
							$element.height(dimension.height);
							$nav.css("zIndex", zIndex++);	
						} else {
							$element.height(dimension.height+$nav.outerHeight(true));
						}
					}
				} else {
					$nav.hide();
					if (dimension.height) {
						$element.height(dimension.height);
					}
				}
			});
			return true;
		}
	};

	// Show media
	show = function(element, lnk, arrMedia) {
		var $element = $(element),
			$link = $(lnk),
			imageId,
			$img, $media;
		
		$element.find("."+settings.navContainer+" a").each(function() {
			$(this).removeClass(settings.activeClassName);
		});
		$link.addClass(settings.activeClassName);
					
		imageId = $link.attr("href").split("#")[1];
		$img = $("#"+imageId);

		if (settings.slide) {
			$element.find("."+settings.mediaContainer).each(function() {
				if ($img.length) {
					$(this).stop().animate({left: "-"+$img.css("left") }, settings.speed);
				}
			});
		} else {
			$.each(arrMedia, function(idx, value) {
				$media = $(value);
				if ($media.is(":visible") && ($img.attr("id")!==$media.attr("id"))) {
					if (settings.navInside) {
						$media.css("bottom",0);
					}
					$media.fadeOut(settings.speed, function() {
						$img.fadeIn(settings.speed);
					});
					return false;
				}								  
			});
		}
	};

	// AutoPlay Show
	playShow = function(element, content, arrMedia, index) {
		var $element = $(element),
			$content = $(content),
			zIndex	= 66666, //$.getHighestZIndex(),
			$nav = $element.find("."+settings.navContainer);
		
		$content.css("zIndex", zIndex);
		$content.fadeIn(settings.speed);
		
		if ($nav.length) {
			$nav.css("zIndex", zIndex++);	
		}

		timerId = setTimeout(function() {
			var nextIdx = index+1>arrMedia.length-1? 0 : index+1;
			play($element, arrMedia, nextIdx, false);
		}, settings.timer*1000);
		
	};	

	// on autoPlay mode
	play = function(element, arrMedia, index, isFirstTimeLoad) {
		if (arrMedia.length) {
			var $element = $(element),
				$img = $(arrMedia[index]),
				$media,
				nextIdx, href;
			
			// get media link
			$element.find("a").each(function() {
				href = $(this).attr("href").split("#")[1];
				if (href === $img.attr("id")) {
					$(this).removeClass(settings.activeClassName).addClass(settings.activeClassName);
				} else {
					$(this).removeClass(settings.activeClassName);
				}
			});

			if (settings.slide) {
				$element.find("."+settings.mediaContainer).each(function() {
					$(this).stop().animate({left: "-"+$img.css("left") }, settings.speed,  function() {
						//interval validation
						if (isNaN(settings.timer)) {
							settings.timer = defaults.timer;
						}
						timerId = setTimeout(function() {
							nextIdx = index+1>arrMedia.length-1? 0 : index+1;
							play($element, arrMedia, nextIdx, false);
						}, settings.timer*1000);
					});
				});
			} else {
				$.each(arrMedia, function(idx, value) {
					$media = $(value);

					if ($media.is(":visible")) {
						if (!isFirstTimeLoad) {
							$media.fadeOut(settings.speed, function() {
								playShow($element, $img, arrMedia, index);
							});
						} else {
							playShow($element, $img, arrMedia, index);
						}
						return false;
					}					  
				});
			}
		}
	};
	
	return this.each(function(idx){
		var $element = $(this),
			$links, media, $link,
			$content, contentId;

		//validateParams
		if (idx ===0) { validateParams(); }

		// Set Carousel dimension
		if (!$.data($element.get(0),"initialized")) {
			if (setDimension($element)) {			
				// error functionality check
				if (window.carouselTimerId) {
					clearTimeout(window.carouselTimerId);	
				}
				
				if (!settings.slide) {
					$element.css("overflow","visible");
				} 
		
				// find links and initialize it
				$links = $element.find("."+settings.navContainer+" a");
				
				if ($links.length > 1) {
					// Get media array
					media = [];
	
					$links.each(function(i) {
						$link = $(this);
						contentId = $link.attr("href").split("#")[1];
						if (i===0) {
							$link.addClass(settings.activeClassName);
						} else {
							$link.removeClass(settings.activeClassName);				
						}
						try {
							$content = $("#"+contentId);
							
							if ($content.length) {
								if (settings.navInside) {
									$content.css("bottom",0);
								}						
								media.push($content);
							}
						} catch(e) {}
						
						$link.unbind("click").click(function() {
							show($element, $(this), media);
							clearTimeout(timerId);
							return false;
						});
					});
					
					// autoPlay mode
					if (settings.autoPlay) {
						play($element, media, 0, true);
					}
				} else if ($links.length === 1) {
					// We only show navigation for at least 2 items
					$links.hide();
				}
				$.data($element.get(0),"initialized",true);
			} else {
				// re-run carousel call
				window.carouselTimerId = setTimeout(function() {
					$element.carousel(settings);
				}, 100);
			}
		}
	});
};
/***************************************************/
// plugin: flyOut
/**********************************************************/
jQuery.fn.flyOut = function(settings) {
	var defaults, mouseOn, validateParams,
		show, hide, startTimer, resetActive,
		setActiveInput, setAlwaysOnTop, generateHTML;
	
	defaults = {
		ajax: false,
		fade: true,
		inputs: false,
		hide: false,
		generateHtml: true, 
		speed: 250,
		className: "",
		itemActiveClassName: "active",
		itemHoverClassName: "hover",
		closeTimer: 250
	};
	settings = $.extend(defaults, settings);

	mouseOn = false;

	// Validate Params
	validateParams = function() {
		if (typeof(settings.ajax) !== "boolean") {
			settings.ajax = false;
		}
		if (typeof(settings.fade) !== "boolean") {
			settings.fade = true;
		}
		if (typeof(settings.inputs) !== "boolean") {
			settings.inputs = true;
		}
		if (typeof(settings.hide) !== "boolean") {
			settings.hide = false;
		}
		if (typeof(settings.generateHtml) !== "boolean") {
			settings.generateHtml = true;
		}
		if (isNaN(settings.speed)) {
			settings.speed = 250;
		}		
		if (typeof(settings.className) !== "string") {
			settings.className = "";
		}				
		if (typeof(settings.contentClassName) !== "string") {
			settings.contentClassName = "flyOut";
		}		
		if (typeof(settings.itemActiveClassName) !== "string") {
			settings.itemActiveClassName = "active";
		}		
		if (isNaN(settings.closeTimer)) {
			settings.closeTimer = 250;
		}		
	};
	
	// show flyOut
	show = function(element) {
		var $element = $(element),
			fromAjax = arguments[1];

		// make sure content will be showned
		$($(".flyOutContJs", $element).children()[0]).show();

		// animate effect		
		if (settings.fade) {
			$element.stop();
			if (fromAjax || $.isIE("<9")) {
				$element.show();
			} else {
				$element.fadeIn(settings.speed);				
			}
		} else {
			$element.show();
		}

		// handling mouse out/leave on element
		$element.mouseover(function() {
			mouseOn = true;
			$element.show();
		}).mouseleave(function() {
			mouseOn = false;
			startTimer($element);
		});
		
		// $.getHighestZIndex()
		$element.css("zIndex", 999999);
	};
	
	// hide flyOut
	hide = function(element) {
		var $element = $(element);
		mouseOn = false;		
		
		if (settings.fade && $.isIE(">8")) {
			$element.fadeOut(settings.speed);
		} else {
			$element.hide();
		}
		
		// IE select always on top fix
		if ($.isIE()) { 
			// remove IE bug overlay links
			$("#"+$element.attr("id")+"-img").remove();
		}		
	};

	// start timer before closing flyOut
	startTimer = function(element) {
		var $element = $(element);		
		window.bradFlyOutTimer = setTimeout(function() {
			clearTimeout(window.bradFlyOutTimer);
			if (!mouseOn) {
				hide($element);
			}
		}, settings.closeTimer);
	};

	resetActive = function(elements) {
		var $elements = $(elements);
		$elements.each(function() {
			$(this).parent().removeClass(settings.itemActiveClassName);						
		});
	};

	setActiveInput = function(content, text) {
		if (settings.inputs) {
			var $inputs = $(content).find(":input"),
				$parent;
				
			resetActive($inputs);
			$inputs.each(function() {
				$parent = $(this).parent();
				if ($.trim($parent.text())===text) {
					$parent.addClass(settings.itemActiveClassName);	
				}
			});
		}
	};

	setAlwaysOnTop = function(content) {
		var $content = $(content),
			$img, src;
		
		// IE PNG check (because IE does not like fade effect when PNG is involve)
		if ($.browser.msie) {
			if ($content.css("backgroundImage").indexOf(".png") !== -1) {
				settings.fade = false;
			} else {
				$content.children().each(function() {
					if ($(this).css("backgroundImage").indexOf(".png") !== -1) {
						settings.fade = false;
						return false;
					}
				});
			}
			
			// IE flyout mouseleave bug fix
			if ($("#"+$content.attr("id")+"-img").length === 0) {
				$img =	$("<img id='"+$content.attr("id")+"-img'></img>");
				$img.addClass("transparent");
				$content.prepend($img);
				
				src = $img.css("backgroundImage").replace("url(","").replace(".png)",".png");
				src = src.substr(0,src.length-1);
				src = src.substr(1,src.length-2);
				$img.attr("src",src);
				$img.css("position", $content.css("position"));
				
				if ($content.css("left") === "auto") {
					if ($content.css("right") !== "auto") {
						$img.css("right", $content.css("right"));								
					}
				} else {
					$img.css("left", $content.css("left"));
				}
				$img.css("top", $content.css("top"));
				$img.width($content.width());
				$img.height($content.height());
				
				$img.mouseenter(function() { mouseOn = true; });
			}
		}		
	};

	generateHTML = function(flyOutId) {
		var rand, html;
		
		if (!flyOutId || flyOutId === "" || flyOutId.indexOf("#")!== -1) {
			rand = Math.floor(Math.random()*1000);
			if ($.isFunction($.getRandomNumber)) {
				rand = $.getRandomNumber();
			}
			flyOutId = "brad-flyOut-"+rand;
		} else {
			flyOutId += "-flyOut"; 
		}
		
		html = "";
		html += "<div id='"+flyOutId+"' class='flyOut "+settings.className+"'>\n";
		html += "	<div class='flyOutBordRight'>\n";
		html += "		<div class='flyOutBordLeft'>\n";
		html += "			<div class='lining flyOutContJs'><\/div>\n";
		html += "		</div>\n";
		html += "	<\/div>\n";
		html += "	<div class='flyOutTopRight'><div class='flyOutTopLeft'><\/div><\/div>\n";
		html += "	<div class='flyOutBottomRight'><div class='flyOutBottomLeft'><\/div><\/div>\n";
		html += "<\/div>\n";
		return html;
	};
	
	return this.each(function(idx){
		var $element = $(this),
			contentId = $element.attr("href").split("#")[1],
			$content = $("#"+contentId);

		//validateParams
		if (idx ===0) { 
			validateParams();
			$("body").click(function() {
				hide($content);
			});
		}
		
		if (settings.hide) {
			hide($content);
		} else {
			if ($content.length) { $content.hide();	}
			
			$element.unbind("click").click(function(idx) {
				var $link = $(this),
					flyOutId, $flyOut, $placeHolder,
					url, rand, loaderEnabled, toBindEventHandling,
					$parent, $inputs, strFor, label, $links, currentText;
				
				// indicate that mouse is on
				mouseOn = true;

				// hide previous flyOut
				$("body").find(".flyOut").each(function() {
					if (settings.ajax) {
						
					} else {
						flyOutId = $(this).attr("id");
						if (flyOutId) {
							if (flyOutId !== contentId+"-flyOut") {
								$(this).hide();	
							}
						}
					}
				});
			
				// Set default selected input based on the link text (if applicable)
				setActiveInput($content, $link.text());

				// Content
				if (settings.ajax) { // Ajax
					url = $link.attr('href');
					
					rand = 0;
					if ($.getRandomNumber) { rand = $.getRandomNumber(); }
					
					if (url.indexOf("&") !== -1) {
						url += "&refreshxyz="+rand;
					} else if (url.indexOf("?") === -1) { 
						url += "?refreshxyz="+rand; 
					}
					
					$flyOut = $.data($link.get(0),"flyOut");
					if (!$flyOut) {
						$flyOut = $(generateHTML());
						$link.after($flyOut);
						$placeHolder = $(".flyOutContJs", $flyOut);
						
						loaderEnabled = false;
						if ($.isFunction($.ajaxLoader.show)) {
							loaderEnabled = true;
							$flyOut.show();
							$placeHolder.addClass("loading");
							$.ajaxLoader.show({targetId:$placeHolder});
						}

						// Loads data synchronously. 
						// Blocks the browser while the requests is active. 
						// It is better to block user interaction by other means when synchronization is necessary.
						$.ajax({
							url: url,
							async: false,
							dataType: "html",
							success: function(data) {
								// place new content
								var $data = $(data);
								$flyOut.addClass($data.attr("class"));
								$data.removeClass("class");
								$placeHolder.prepend(data).removeClass("loading");

								if (loaderEnabled) {
									$.ajaxLoader.hide({targetId:$placeHolder});
								}
								
								show($flyOut, true);

								// handling mouse out/leave on the link
								$link.mouseover(function() {
									mouseOn = true;
								}).mouseleave(function() {
									mouseOn = false;
									startTimer($flyOut);
								});
									
								// save state
								$.data($link.get(0),"flyOut", $flyOut);
							},
							error: function() {
								var defErrorText = "Error";
								if ($.isFunction($.getText)) {
									defErrorText = $.getText("error");
								}
								/*global alert */
								alert(defErrorText);
							}							
						});

					} else {
						if (!$flyOut.is(":visible")) {
							show($flyOut);	
							// handling mouse out/leave on the link
							$link.mouseover(function() {
								mouseOn = true;
							}).mouseleave(function() {
								mouseOn = false;
								startTimer($flyOut);
							});						
						} else {
							hide($flyOut);
						}
					}
				} else {  // In Page
				
					// create new flyOut?
					toBindEventHandling = false;
					if (settings.generateHtml) {
						flyOutId = contentId+"-flyOut";
						$flyOut = $("#"+flyOutId);
					} else if ($content.length) {
						toBindEventHandling = true;
						$flyOut = $content;
					}

					if ($flyOut.length === 0 || toBindEventHandling) {
						// content handling
						if ($content.length) {
						
							// main element mouseout handling
							$link.unbind("mouseleave").mouseleave(function() {
								mouseOn = false;
								startTimer($flyOut);										  
							});
						
							if (settings.generateHtml) {
								$flyOut = $(generateHTML(contentId));
								$flyOut.addClass($content.attr("class"));
								$content.removeAttr("class");
								
								// move content in flyOut
								$content.after($flyOut);
								$content.show();
								$placeHolder = $(".flyOutContJs", $flyOut);
								$placeHolder.append($content);
							} 
							
							// transparent layer workaround
							setAlwaysOnTop($flyOut);

							if (!$flyOut.is(":visible")) {
								// Handling flyOut types
								if (settings.inputs) {
									$inputs = $content.find(":input");
									$inputs.each(function() {
										// Click
										$(this).unbind("click").click(function() {
											strFor = $(this).attr("id");
											resetActive($inputs);
											$parent = $(this).parent();	
											$parent.addClass(settings.itemActiveClassName);
											label = $parent.find("label[for='"+strFor+"']").text();
											$element.text(label);
											$flyOut.hide();								
										});
										// Mouse hover
										$(this).parent().find("label:first").hover(function() {
											$(this).addClass(settings.itemHoverClassName);									   
										}, function() {
											$(this).removeClass(settings.itemHoverClassName);									
										});
										
										if($.browser.msie) {
											$(this).parent().find("label:first").unbind("click").click(function() {
												resetActive($inputs);
												$(this).parent().addClass(settings.itemActiveClassName);
												$element.text($(this).text());
												$flyOut.hide();
											});
										}
									});
								} else {
									$links = $flyOut.find("a");
									$links.each(function() {
										$(this).unbind("click").click(function() {
											currentText = $element.text();
											$element.html($element.html().replace(currentText,$(this).text()));
											resetActive($links);
											$(this).parent().addClass(settings.itemActiveClassName);									
											window.location.href = $(this).attr("href");									
										});
									});
								}
								show($flyOut);						
							} 
						}
					} else { // flyOut already generated
						if (!$flyOut.is(":visible")) {
							show($flyOut); 
						} else {
							hide($flyOut);
						}
					}
				}
				return false;						
			});
		}
	});
};
/***************************************************/
// plugin: tabbing (TODO: rework history manager form IE)

/**********************************************************/
jQuery.fn.tabbing = function(settings) {
	var defaults, validateParams,
		historyManager, show, historyLookUp;
	
	defaults = {
		slugHash: "-tabs",
		slugContent: "-content",
		linksContainerClassName : "tabTrigSet",
		linkActiveClassName : "tabTrigActive",
		contentContainerClassName: "tabContSet",
		contentClassName: "tabCont",
		contentActiveClassName: "tabContActive",
		opacity: 50
	};
	settings = $.extend(defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.slugHash) !== "string") {
			settings.slugHash = "-tabs";
		}
		if (typeof(settings.slugContent) !== "string") {
			settings.slugContent = "-content";
		}
		if (typeof(settings.linksContainerClassName) !== "string") {
			settings.linksContainerClassName = "tabTrigSet";
		}
		if (typeof(settings.linkActiveClassName) !== "string") {
			settings.linkActiveClassName = "tabTrigActive";
		}
		if (typeof(settings.contentContainerClassName) !== "string") {
			settings.contentContainerClassName = "tabContSet";
		}
		if (typeof(settings.contentClassName) !== "string") {
			settings.contentClassName = "tabCont";
		}
		if (typeof(settings.contentActiveClassName) !== "string") {
			settings.contentActiveClassName = "tabContActive";
		}
		if (isNaN(settings.opacity)) {
			settings.opacity = 50;
		}
	};

	// IE history Manager
	historyManager = {
		init: function(element) {
			if($.isIE("<9")) {
				var $iframe = $("#history_manager"),
					$element, $myGroup, $myTabs, $activeTab, iframe;
				
				if ($iframe.length === 0) {
					$iframe = $("<iframe id='history_manager' style='display: none;'><\/iframe>");
					$("body").prepend($iframe);
					if (window.location.hash.indexOf(settings.slugHash) === -1) {
						// When no hash in url we have to set initial hash in iframe
						$element = $(element);
						$myGroup = $element.find("."+settings.linksContainerClassName);				
						$myTabs = $myGroup.find('a');
				
						$activeTab = $myGroup.find("."+settings.linkActiveClassName+":first");
						iframe = $iframe[0].contentDocument || $iframe[0].contentWindow.document;
						iframe.open();
						iframe.close();
						iframe.location.hash = $activeTab.length > 0? "#"+$($activeTab[0]).attr("id") : "#"+$($myTabs[0]).attr("id");
					}
				} 
			}
		},
		add : function() {
			var $iframe = $("#history_manager"), iframe;
			
			if ($iframe.length) {
				iframe = $iframe[0].contentDocument || $iframe[0].contentWindow.document;
				iframe.open();
				iframe.close();
				iframe.location.hash = window.location.hash.replace(settings.slugHash,'');
			}
		},
		goTo : function(selector, idLink) {
			var $iframe = $("#history_manager"), iframe;
			
			if ($iframe.length) {
				iframe = $iframe[0].contentDocument || $iframe[0].contentWindow.document;
				
				// We need to avoid multiple call to the show function
				if (window.location.hash.replace(settings.slugHash,'') !== iframe.location.hash && iframe.location.hash !== "") {
					show($(selector), $(iframe.location.hash));
					// reset the hash onced showned
					window.location.hash = iframe.location.hash;
				} else {
					if (!$("#"+idLink.attr("id")+settings.slugContent).hasClass(settings.contentActiveClassName)) {
						show($(selector), idLink);	
					}
				}
			}
		}
	};

	show = function(selector, element, fromHistoryLookUp) {
		var $selector = $(selector),
			$element = $(element),
			$myGroup = $selector.find("."+settings.linksContainerClassName),
			$myCont = $selector.find("."+settings.contentClassName),
			url, $container, strDiv, $tab, $tabContent,
			rand, isIELowerThan9 = $.isIE("<9"), rel;

		// Get url to send to AJAX
		url = $element.attr('href');

		strDiv = $element.attr("id")+settings.slugContent;
		$tab = $("."+settings.contentContainerClassName);
		$tabContent = $("#"+strDiv);
		
		if ($tabContent.length === 0 && typeof($element.attr("id"))!=="undefined") {
			$container = $("<div class='"+settings.contentClassName+"' id='"+strDiv+"'></div>");
			$tab.css("opacity", settings.opacity/100);
			$tab.append($container);
			$.ajaxLoader.show();
			
			// Loads data synchronously. 
			// Blocks the browser while the requests is active. 
			// It is better to block user interaction by other means when synchronization is necessary.
			rand = Math.floor(Math.random()*100);
			if (url.indexOf("&") !== -1) {
				url += "&refreshxyz="+rand;
			} else if (url.indexOf("?") === -1) {
				url += "?refreshxyz="+rand;
			}
			$.ajax({
				url: url,
				async: false,
				success: function(data) {
					$.ajaxLoader.hide();
					$container.html(data);
					
					$tab.css("opacity", 1);
					
					// Finally apply hasLayout
					if (isIELowerThan9) {
						$tab.removeAttr("style");
						window.bradTabsTimer = setTimeout(function() {
							clearTimeout(window.bradTabsTimer);
							$.hasLayout($selector);
							window.bradTabsTimer = setTimeout(function() { 
								clearTimeout(window.bradTabsTimer);
								$.hasLayout($container); 
							}, 100);
						}, 100);
					}

					$myGroup.find("."+settings.linkActiveClassName).removeClass(settings.linkActiveClassName);
					$myCont.parent().find("."+settings.contentActiveClassName).removeClass(settings.contentActiveClassName);
					$element.addClass(settings.linkActiveClassName);
					
					$container.addClass(settings.contentActiveClassName);
			
					// Specific to  otherwise we can remove this part
					if ($.isFunction($.pageRender)) {
						$.pageRender($container, "tabs");
					}
				},
				error: function() {
					var defErrorText = "Error";
					if ($.isFunction($.getText)) {
						$container.html($.getText("error"));
					} else {
						$container.html(defErrorText);
					}									
				}
			});
		} else {
			$myGroup.find("."+settings.linkActiveClassName).removeClass(settings.linkActiveClassName);
			$myCont.parent().find("."+settings.contentActiveClassName).removeClass(settings.contentActiveClassName);
			$element.addClass(settings.linkActiveClassName);
			
			$container = $("#"+strDiv);
			$container.addClass(settings.contentActiveClassName);
			
			// Specific to  otherwise we can remove this part
			if ($.isFunction($.pageRender) && !$.data($container.get(0),"renderInitialized")) {
				$.pageRender($container, "tabs");
				$.data($container.get(0),"renderInitialized", true);
			}				
		}

		if (!fromHistoryLookUp) {
			// Omniture
			// TODO: refactor this code to use $.brad.external
			rel = $element.attr("rel");
			/*global manageTabTracking */
			if (typeof(manageTabTracking) !== "undefined" && window.bradToTrackTab) {
				if (rel) {
					window.bradToTrackTab = false;				
					manageTabTracking(rel);
				}
			}
			
			// LivePerson
			if ($.brad.external) {
				if (!rel) { rel = $element.text(); }
				if ($.isFunction($.brad.external.tracker)) {
					$.brad.external.tracker({
						appName: "lp",
						actionName: "tabs",
						data: {
							tabLabel: rel.indexOf("/")===-1?rel:rel.split("/")[1]	
						}
					});
				}
			}
		}

		// Finally apply hasLayout for IE < IE9
		if (isIELowerThan9) {
			window.bradHasLayoutTimer = setTimeout(function() {
				clearTimeout(window.bradHasLayoutTimer);
				$.hasLayout($selector);
				window.bradHasLayoutTimer = setTimeout(function() { 
					clearTimeout(window.bradHasLayoutTimer);	
					$.hasLayout($container); 
				}, 100);
			}, 100);
		}
	};

	historyLookUp = function(selector) {
		var hash = window.location.hash,
			idLink = hash;
			
		if (hash!=="") {
			if (hash.indexOf(settings.slugHash) !== -1) {
				idLink = hash.split(settings.slugHash)[0];
			} 
			if (!$.isIE("<9")) {
				show($(selector), $(idLink), true); // add true flag indicating the show is coming from historyLookUp
			} else {
				historyManager.goTo($(selector), $(idLink));
			}
		}
	};	

	return this.each(function(idx){
		var $element = $(this),
			$myGroup = $element.find("."+settings.linksContainerClassName),
			$myTabs = $myGroup.find('a'),
			$activeTab, $myCont;

		//validateParams
		if (idx ===0) {
			window.bradToTrackTab = true;			
			
			// Load initial active tab Data
			$activeTab = $myGroup.find("."+settings.linkActiveClassName+":first");
			if ($activeTab.length) {
				$myCont = $element.find("."+settings.contentClassName);
				if ($myCont.length) {
					$myCont.addClass(settings.contentActiveClassName);
				}
			} else {
				show($element, $activeTab.length > 0? $activeTab[0] : $myTabs[0]);
			}
			historyManager.init($element);			
			
			if (!$.isIE() || !$.isIE("<9")) {
				/*global setInterval */
				setInterval(historyLookUp, 100, $element);
			}
		}

		// Click behavior of the links
		if (!$.data($myTabs.get(0),"tabsInitialized")) {
			$myTabs.each(function() {
				$(this).click(function(){
					var $link = $(this);
					
					window.bradToTrackTab = true;
					window.location.hash = $link.attr("id")+settings.slugHash;
					
					// history handling not handled for now on IE					
					/*
					if ($.isIE("<9")) {
						historyManager.add();
					}
					*/
					show($element, $link);
					return false;
				});
			});
			$.data($myTabs.get(0),"tabsInitialized", true);
		}
	});
};
/***************************************************/
// jQuery function: pageRender()
/**********************************************************/
jQuery.pageRender = function(context, useCase) {
	if (typeof($.brad) === "object") {
		if (typeof($.brad.page) === "object") {
			if ($.isFunction($.brad.page.render)) {
				var fn = $.getCallBack(arguments);
				$.brad.page.render(context, useCase, fn);
			}
		}
	}
};









/***************************************************/
//	Function: $.labelOver()
/**********************************************************/
jQuery.fn.labelOver = function(settings) {
	var defaults, validateParams;
	
	defaults = {
		hideClassName: 'accessAlt'
	};
	
	settings = $.extend(defaults, settings);

	// Validate Params
	validateParams = function() {
		if (typeof(settings.hideClassName) !== "string") {
			settings.hideClassName = "accessAlt";
		}
	};

	return this.each(function(idx) {
		if (idx === 0) { validateParams(); }									  
							  
		var $label = $(this),
			labelFor = $label.attr('for'), $input;
		
		if (labelFor){
			$input = $('#'+labelFor);
			$label.addClass('labelOverAct').insertBefore($input);

			if ($input.val()) {
				$label.addClass(settings.hideClassName);
			} else if ($.isIE("<9")) {
				$label.css("zoom",1);
			}
			
			$input.focus(function(){
				$label.addClass(settings.hideClassName);
			});
			
			$input.blur(function(){
				if (!$(this).val()) {
					$label.removeClass(settings.hideClassName);
				}
			});
		}
	});
};


})(jQuery);
