(function($){
	//add class to html tag
	$('html').addClass('stylish-select');

	//create cross-browser indexOf
	Array.prototype.indexOf = function (obj, start) {
		for (var i = (start || 0); i < this.length; i++) {
			if (this[i] == obj) {
				return i;
			}
		}
	}

	//utility methods
	$.fn.extend({
		getSetSSValue: function(value){
			if (value){
				//set value and trigger change event
				$(this).val(value).change();
				return this;
			} else {
				return $(this).find(':selected').val();
			}
		},
		//added by Justin Beasley
		resetSS: function(){
			var oldOpts = $(this).data('ssOpts');
			$this = $(this);
			$this.next().remove();
			//unbind all events and redraw
			$this.unbind('.SSelect').SSelect(oldOpts);
		}
	});

	$.fn.SSelect = function(options) {

		return this.each(function(){

		var defaults = {
			defaultText: 'Please select',
			animationSpeed: 0, //set speed of dropdown
			ddMaxHeight: '', //set css max-height value of dropdown
			containerClass: '' //additional classes for container div
		};

		//initial variables
		var opts = $.extend(defaults, options),
		$input = $(this),
		$containerDivText = $('<div class="selectedTxt"></div>'),
		$containerDiv = $('<div class="newListSelected ' + opts.containerClass + '"></div>'),
		$newUl = $('<ul class="newList" style="visibility:hidden;"></ul>'),
		itemIndex = -1,
		currentIndex = -1,
		keys = [],
		prevKey = false,
		prevented = false,
		$newLi;

		//added by Justin Beasley
		$(this).data('ssOpts',options);

		//build new list
		$containerDiv.insertAfter($input);
		$containerDiv.attr("tabindex", $input.attr("tabindex") || "0");
		$containerDivText.prependTo($containerDiv);
		$newUl.appendTo($containerDiv);
		
		$input.css({"position" : "absolute", "left" : "-99999px"});

		//added by Justin Beasley (used for lists initialized while hidden)
		$containerDivText.data('ssReRender',!$containerDivText.is(':visible'));

            //test for optgroup
            if ($input.children('optgroup').length == 0){
                $input.children().each(function(i){
                    var option = $(this).html();
                    var key = $(this).val();

                    //add first letter of each word to array
                    keys.push(option.charAt(0).toLowerCase());
                    if ($(this).attr('selected') == true){
                        opts.defaultText = option;
                        currentIndex = i;
                    }
                    $newUl.append($('<li><a href="javaScript:void(0);">'+option+'</a></li>').data('key', key));

                });
                //cache list items object
                $newLi = $newUl.children().children();

            } else { //optgroup
                $input.children('optgroup').each(function(){

                    var optionTitle = $(this).attr('label'),
                    $optGroup = $('<li class="newListOptionTitle">'+optionTitle+'</li>');

                    $optGroup.appendTo($newUl);

                    var $optGroupList = $('<ul></ul>');

                    $optGroupList.appendTo($optGroup);

                    $(this).children().each(function(){
                        ++itemIndex;
                        var option = $(this).html();
                        var key = $(this).val();
                        //add first letter of each word to array
                        keys.push(option.charAt(0).toLowerCase());
                        if ($(this).attr('selected') == true){
                            opts.defaultText = option;
                            currentIndex = itemIndex;
							
                        }
                        $optGroupList.append($('<li><a href="javaScript:void(0);">'+option+'</a></li>').data('key',key));
                    })
                });
                //cache list items object
                $newLi = $newUl.find('ul li a');
            }

            //get heights of new elements for use later
            var newUlHeight = $newUl.height(),
            containerHeight = $containerDiv.height(),
            newLiLength = $newLi.length;

            //check if a value is selected
            if (currentIndex != -1){
                navigateList(currentIndex, true);
				
            } else {
                //set placeholder text
                $containerDivText.text(opts.defaultText);
				
            }

            //decide if to place the new list above or below the drop-down
            function newUlPos(){
                var containerPosY = $containerDiv.offset().top,
                docHeight = jQuery(window).height(),
                scrollTop = jQuery(window).scrollTop();

                //if height of list is greater then max height, set list height to max height value
                if (newUlHeight > parseInt(opts.ddMaxHeight)) {
                    newUlHeight = parseInt(opts.ddMaxHeight);
                }

                containerPosY = containerPosY-scrollTop;
                if (containerPosY+newUlHeight >= docHeight){
                    $newUl.css({
                        top: '-'+newUlHeight+'px',
                        height: newUlHeight
                    });
                    $input.onTop = true;
                } else {
                    $newUl.css({
                        top: containerHeight+'px',
                        height: newUlHeight
                    });
                    $input.onTop = false;
                }
            }

            //run function on page load
            newUlPos();

            //run function on browser window resize
			$(window).bind('resize.SSelect scroll.SSelect', newUlPos);

            //positioning
            function positionFix(){
                $containerDiv.css('position','relative');
            }

            function positionHideFix(){
                $containerDiv.css('position','static');
            }

            $containerDivText.bind('click.SSelect',function(event){
                event.stopPropagation();
				

				//added by Justin Beasley
				if($(this).data('ssReRender')) {
					newUlHeight = $newUl.height('').height();
					containerHeight = $containerDiv.height();
					$(this).data('ssReRender',false);
					newUlPos();
				}

                //hide all menus apart from this one
				$('.newList').not($(this).next()).hide()
                    .parent()
                        .css('position', 'static')
                        .removeClass('newListSelFocus');

                //show/hide this menu
                $newUl.toggle();
                positionFix();
                //scroll list to selected item
                $newLi.eq(currentIndex).focus();
				

            });

            $newLi.bind('click.SSelect',function(e){
                var $clickedLi = $(e.target);

                //update counter
                currentIndex = $newLi.index($clickedLi);
				// Made Selecte box selected
				$(this).parent().parent().parent().prev().children().attr('selected', false)
				$(this).parent().parent().parent().prev().children().eq(currentIndex).attr('selected', true)
				
                //remove all hilites, then add hilite to selected item
                prevented = true;
                navigateList(currentIndex);
                $newUl.hide();
                $containerDiv.css('position','static');//ie

            });

            $newLi.bind('mouseenter.SSelect',
				function(e) {
					var $hoveredLi = $(e.target);
					$hoveredLi.addClass('newListHover');
				}
			).bind('mouseleave.SSelect',
				function(e) {
					var $hoveredLi = $(e.target);
					$hoveredLi.removeClass('newListHover');
				}
			);

            function navigateList(currentIndex, init){
                $newLi.removeClass('hiLite')
                .eq(currentIndex)
                .addClass('hiLite');

                if ($newUl.is(':visible')){
                    $newLi.eq(currentIndex).focus();
                }

                var text = $newLi.eq(currentIndex).html();
                var val = $newLi.eq(currentIndex).parent().data('key');

                //page load
                if (init == true){
                    $input.val(val);
                    $containerDivText.text(text);
                    return false;
                }

		try {
		    $input.val(val)
		} catch(ex) {
		    // handle ie6 exception
		    $input[0].selectedIndex = currentIndex;
		}

                $input.change();
                $containerDivText.text(text);
            }

            $input.bind('change.SSelect',function(event){
                $targetInput = $(event.target);
                //stop change function from firing
                if (prevented == true){
                    prevented = false;
                    return false;
                }
                $currentOpt = $targetInput.find(':selected');

                //currentIndex = $targetInput.find('option').index($currentOpt);
                currentIndex = $targetInput.find('option').index($currentOpt);

                navigateList(currentIndex, true);
			});

            //handle up and down keys
            function keyPress(element) {
                //when keys are pressed
                $(element).unbind('keydown.SSelect').bind('keydown.SSelect',function(e){
                    var keycode = e.which;

                    //prevent change function from firing
                    prevented = true;

                    switch(keycode) {
                        case 40: //down
                        case 39: //right
                            incrementList();
                            return false;
                            break;
                        case 38: //up
                        case 37: //left
                            decrementList();
                            return false;
                            break;
                        case 33: //page up
                        case 36: //home
                            gotoFirst();
                            return false;
                            break;
                        case 34: //page down
                        case 35: //end
                            gotoLast();
                            return false;
                            break;
                        case 13:
                        case 27:
                            $newUl.hide();
                            positionHideFix();
                            return false;
                            break;
                    }

                    //check for keyboard shortcuts
                    keyPressed = String.fromCharCode(keycode).toLowerCase();

                    var currentKeyIndex = keys.indexOf(keyPressed);

                    if (typeof currentKeyIndex != 'undefined') { //if key code found in array
                        ++currentIndex;
                        currentIndex = keys.indexOf(keyPressed, currentIndex); //search array from current index
                        if (currentIndex == -1 || currentIndex == null || prevKey != keyPressed) currentIndex = keys.indexOf(keyPressed); //if no entry was found or new key pressed search from start of array


                        navigateList(currentIndex);
                        //store last key pressed
                        prevKey = keyPressed;
                        return false;
                    }
                });
            }

            function incrementList(){
                if (currentIndex < (newLiLength-1)) {
                    ++currentIndex;
                    navigateList(currentIndex);
                }
            }

            function decrementList(){
                if (currentIndex > 0) {
                    --currentIndex;
                    navigateList(currentIndex);
                }
            }

            function gotoFirst(){
                currentIndex = 0;
                navigateList(currentIndex);

            }

            function gotoLast(){
                currentIndex = newLiLength-1;
                navigateList(currentIndex);
            }

            $containerDiv.bind('click.SSelect',function(e){
                e.stopPropagation();
                keyPress(this);
            });

            $containerDiv.bind('focus.SSelect',function(){
                $(this).addClass('newListSelFocus');
                keyPress(this);
            });

            $containerDiv.bind('blur.SSelect',function(){
                $(this).removeClass('newListSelFocus');
            });

            //hide list on blur
            $(document).bind('click.SSelect',function(){
                $containerDiv.removeClass('newListSelFocus');
                $newUl.hide();
                positionHideFix();
            });

            //add classes on hover
            $containerDivText.bind('mouseenter.SSelect',
				function(e) {
					var $hoveredTxt = $(e.target);
					$hoveredTxt.parent().addClass('newListSelHover');
				}
			).bind('mouseleave.SSelect',
				function(e) {
					var $hoveredTxt = $(e.target);
					$hoveredTxt.parent().removeClass('newListSelHover');
				}
            );

            //reset left property and hide
            $newUl.css({
                left: '-1px',
                display: 'none',
                visibility: 'visible'
            });

        });

    };

})(jQuery);

$(function(){
		   
	/**
	* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
	* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
	* 
	* @param  f  onMouseOver function || An object with configuration options
	* @param  g  onMouseOut function  || Nothing (use configuration options object)
	* @author    Brian Cherne brian(at)cherne(dot)net
	*/
	
	$.fn.hoverIntent=function(f,g){var cfg={sensitivity:10,interval:10,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}
		   
/* Curve Box 
----------------------------------*/
	
$.fn.curveBorder = function(options)
	{
		var defaults = 
			{
				curveStringAll : "<span class='top-left'></span><span class='top-right'></span><span class='btm-left'></span><span class='btm-right'></span>",
				curveStringBottom : "<span class='btm-left'></span><span class='btm-right'></span>",
				radius : 8,
				bgImagePath : "Resources/Images/background/",
				bgImagePathType : "png",
				curveElementClasses : ".top-left,.top-right,.btm-left,.btm-right",
				leftPillHeadingClass : "leftPillHeading",
				rightPillHeadingClass : "rightPillHeading",
				centerPillHeadingClass : "centerPillHeading",
				spotlightCarousel : false,
				withoutTopCurves : false
			};
			var settings = $.extend({},defaults,options);
			var browser = $.browser;

			$(this).each(function(){
				$(this).prepend(settings.withoutTopCurves);
					if(settings.withoutTopCurves)
						{
							$(this).prepend(settings.curveStringBottom);
						}
					else 
						{
							$(this).prepend(settings.curveStringAll);
						}
					
					$(settings.curveElementClasses).css({"background-image" : "url(/" + settings.bgImagePath +"curve-"+ settings.radius + "px" +  "." + settings.bgImagePathType + ")", "background-repeat" : "no-repeat"});
		
				var headingPill = $(this).find(".box-heading, .box-heading-orange");
				if($(this).hasClass(settings.centerPillHeadingClass))
					{
						var left = $(this).width() / 2 - $(headingPill).outerWidth() / 2;
 						$(headingPill).css("left" , left)
					}
				
					
		})
	}
	
/* Curve Box - Ends
----------------------------------*/

/* Spotlight - 7 
----------------------------------*/
	
$.fn.spotlight7 = function(options)
	{
		var defaults = 
			{
				
			};
			var settings = $.extend({},defaults,options);
			var browser = $.browser;

			$(this).each(function(){  
				
				var buttonStrip = $(".buttonStrip", this),
					spotlightWidth = $(this).width();
					
				var margin = (spotlightWidth / 2) - (buttonStrip.width() / 2);
				$(buttonStrip).css("margin-left", Math.round(margin)+"px");
  				
			})
	}
	
/* Spotlight - 7 
----------------------------------*/

/* doveUITabs
----------------------------------*/
	
$.fn.doveUITabs = function(options)
	{
		var defaults = 
			{
				tabClickCallBack : null,
				defaultTab : ""
			};
			var settings = $.extend({},defaults,options);
			var browser = $.browser;

			$(this).each(function(){
								  
				var element = $(this),
					innerWidth = $(this).innerWidth(),
					totalTab = $(".UITabPanel", element).length,
					extraWidth = 16 * totalTab,
					tabWidth = Math.floor((innerWidth - extraWidth) / totalTab),
					totalNewWidth = tabWidth * totalTab,
					diffrence = innerWidth - (totalNewWidth + (16 * totalTab));
					
				$(".tabsCont", element).remove();
				
				var TabCont = $('<div class="tabsCont"></div>'),
					innerTabsCont = $('<div class="innerTabsCont"></div>').appendTo(TabCont),
					TabListing = $('<ul>').appendTo(innerTabsCont);
					
					if(totalTab > 3)
						{
							diffrence = diffrence + ( totalTab - 3 );
						}
					else if (totalTab === 2)
						{
							diffrence = -1;
						}
					else if (totalTab === 1)
						{
							diffrence = -2;
						}
					
				$(".UITabPanel", element).each(function(i){
							
							var panel = $(this),
								tab = $("<li>"),
								tbWidth = tabWidth,
								lastTab,
								activeClass = "", 
								productLength = $(".productDetailLayout").length;
							/*	
							if(tabWidth > 300)
								{
									tbWidth = 200;
									lastTab = "";
								}
							else 
								{
									tbWidth = tabWidth;
									lastTab = "last-tab";
								}
							*/
							if( i != 0 ) {panel.hide();}
							else { tab.addClass("active-tab first-tab");}
							if( (i + 1) == totalTab ) { tab.addClass(lastTab); tbWidth = (diffrence + tbWidth);}

							
							tab
							.html('<a href="#'+ $(this).attr("title") +'" title="'+ $(this).attr("title") +'"><span style="width:'+tbWidth+'px">'+ $(this).attr("title") +'</span></a>')
							.click(function(e){
									e.preventDefault();
									$(".active-tab", element).removeClass("active-tab")
									$(this).addClass("active-tab")
									$(".UITabPanel", element).hide();
									panel.show();									
									if(typeof settings.tabClickCallBack === "function") { settings.tabClickCallBack({tabName : $(this).attr("title"), index : i}); }
									
									if( productLength > 0)
										{
											var tabname = $("a", this).attr("title").toLowerCase() + "Click";
											ntptEventTag("ev="+ tabname +"&link=" +document.location.href);
										}
							})
							.hover(function(){
									$(this).addClass("hover-tab")		
							}, function(){
								$(this).removeClass("hover-tab")
							})
							.appendTo(TabListing);				
				})
				
				
				$(element).prepend(TabCont);
								
				setTimeout(function(){
					
					if(settings.defaultTab !== "")
						{
							$("a[title="+settings.defaultTab+"]").click();	
						}				
				}, 250)
			
			})
	}
	
/* doveUITabs - Ends
----------------------------------*/





/* Spolight Carousel
----------------------------------*/
	
$.fn.spotlightCarousel = function(options)
	{ 
		var defaults = {
		speed 				:	1000,
		showStrip 			: 	true,
		imagestripClass 	: 	"indicatorStrip",
		slideActiveClass 	: 	"active",
		auto				:	true,
		pause				: 	5000
		}; 
		var options = jQuery.extend(defaults, options); 
		
		// Creating Object for this
			var element = this;
			jQuery(element).each(function(){
				var o = this;
				var totalPanels = jQuery('.slide', o).length ,currentImgActive = 1,timeOut;
				//jQuery('.slide:not(:first)', o).css("display", "none")
				if (totalPanels > 1)
					{
						if (options.showStrip)
							{
								var ul = jQuery('<ul>')
								.hide()
								.appendTo(o)
								.addClass(options.imagestripClass)
								.wrap("<div class='indicatorStripCont'><div class='indicatorStripContInner'></div></div>");
								var i = 1;
								for(i; i <= totalPanels; i++)
									{	
										var li = jQuery("<li>")
										if(i == 1)
											var li = jQuery("<li>").addClass("active");
										else
											
											var li = jQuery("<li>");
										
							
										$(li).attr("data-slide", i).hover(function(){ jQuery(this).addClass("hover") },function(){ jQuery(this).removeClass("hover")})
										.click(function()
											{
												changeImages($(this).attr("data-slide"))
											})
										.html('<span class='+"slideNumber-" + i +'>'+ i +'</span>')
										.appendTo(ul, o);
										
									}
								
								var totalWidth = $(o).width(), stripWdith = $(ul).width();
								var width = (totalWidth / 2) - (stripWdith / 2)
								
								indicatorStripCont = $(o).find(".indicatorStripCont")
								indicatorStripCont.css({left:width});
								ul.show();
									
							}
							
							function changeImages(object)
								{ 	
									if (object == 0) { object = 1 }
									if (object > totalPanels) { object = 1 }
									jQuery('.slideList .slide', o).not(jQuery('.slideList slide:nth-child(' + currentImgActive + ')', o)).css("display","none"); 				
									
									jQuery(jQuery('.slideList .slide:nth-child(' + currentImgActive + ')', o)).css("z-index",0);								
									jQuery(jQuery('.slideList .slide:nth-child(' + object + ')'),o).css("z-index",1000);				
									
									jQuery('.indicatorStrip li', o).removeClass("active");
									jQuery(jQuery('.indicatorStrip li:nth-child(' + object + ')', o)).addClass("active");
									jQuery(jQuery('.slideList .slide:nth-child(' + object + ')', o)).stop().fadeIn(options.speed); 
									currentImgActive = object;	
									clearTimeout(timeout);
									if (options.auto)
										{		
											autoChange()
										}
								}
								
							function autoChange()
								{		  
									timeout = setTimeout(function(){ changeImages(currentImgActive + 1);},options.pause);		
								}				
							if (options.auto){autoChange();}	
							
						}
				
				
										  
			});
	}
	
/* Spolight Carousel
----------------------------------*/
});

