//a Rapp modified easy scroll
(function(a){a.fn.easyscroll=function(b){var c={speed:5,scrollerheight:476};return this.each(function(){if(b){a.extend(c,b)}var d=["Scroll Up","Scroll Down"];var e=["btnUp","btnDown"];var f=document.getElementById(this.id);f.up=false;f.down=false;f.fast=false;if(!a("#easyscroll").length){var g=document.createElement("div");var h=f.parentNode;g.id="easyscroll";h.insertBefore(g,f);h.removeChild(f);g.style.position="relative";g.style.height=c.scrollerheight+"px";g.style.overflow="hidden";f.style.position="absolute";f.style.top="0";f.style.left="0";g.appendChild(f)}else{document.getElementById("easyscroll").style.height=c.scrollerheight+"px"}var i=document.getElementById("btnUp");var j=document.getElementById("btnDown");i.onmouseover=function(){f.up=true};i.onmouseout=function(){f.up=false};j.onmouseover=function(){f.down=true};j.onmouseout=function(){f.down=false};i.onmousedown=j.onmousedown=function(){f.fast=true};i.onmouseup=j.onmouseup=function(){f.fast=false};i.onclick=function(){f.up=true;return false};j.onclick=function(){f.down=true;return false};f.interval=setInterval(function(){var a;var b=f.offsetHeight;var d=f.offsetTop;var e=f.fast?2:1;if(f.down){a=b+d>c.scrollerheight?d-c.speed*e:d;f.style.top=a+"px"}if(f.up){a=d<0?d+c.speed*e:d;f.style.top=a+"px"}},25)})}})(jQuery)

jQuery(window).load(function() {
    jQuery("div#makeMeScrollable").smoothDivScroll({
        autoScroll: "" ,
        autoScrollDirection: "backandforth",
        autoScrollStep: 1,
        autoScrollInterval: 20,
        visibleHotSpots: "always",
        mouseDownSpeedBooster:2
    });
    
   jQuery('.scrollingHotSpotRight').css({display:'block'});
   jQuery('.scrollingHotSpotLeft').css({display:'block'});
});

jQuery(document).ready(function () {
    

// vertical accordion press nav
    jQuery('#collections_nav').dcAccordion({
            eventType: 'click',
            hoverDelay: 200,
            speed: 'slow',
            saveState: false,
            autoExpand: true
    });

    // init vertical carousel

    // highlight first thumbnail
    jQuery('#collections-slider #scrollthumbs a').eq(0).addClass('selected');

    // grab thumbnail and change large image with it's img src
    jQuery('#collections-slider #scrollthumbs a').live('hover', function(e){
            e.preventDefault();

            jQuery('#collections-slider #scrollthumbs a').removeClass('selected');
            jQuery(this).addClass('selected');
            var thumbImgSrc = jQuery(this).children('img').attr('src');

            jQuery('#collections-main-image img').attr('src',thumbImgSrc);

    });

    jQuery('#scrollthumbs').easyscroll({'scrollerheight':476});
 
 if (jQuery('.collections-wrapper').hasClass('portrait')) { 
	jQuery('#scrollthumbs').easyscroll({'scrollerheight':650});
}

    // show loading message
    jQuery("#loading").ajaxStart(function(){
       jQuery(this).show();
     });
     jQuery("#loading").ajaxStop(function(){
       jQuery(this).hide();
     });

    // populate page
    jQuery('#collections_nav li ul a').live('click', function(e){
            e.preventDefault();

            var collection_year = jQuery(this).attr('href').replace("#","");
            var collection_season = jQuery(this).html().replace(/ /g,"_").toLowerCase();
            var collection_dir = "/skin/frontend/marahoffman/default/images/collections/populate.php?imgdir="+collection_year+"/"+collection_season+"/";
            var collectionsTitle = jQuery(this).attr('rel');

            jQuery('#collections-title').html(collectionsTitle);

            jQuery.ajax({
                    url: collection_dir,
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    success: function(data) {
                            // clear, re-populate, re-init right vertical carousel
                            jQuery('#collections-slider #scrollthumbs').html('');

                            var srcImgWidth = data.width;
                            var thumbImgWidth = '';

                            if (srcImgWidth > 430 ) {
                                    thumbImgWidth = 120;
                                    jQuery('.collections-wrapper').removeClass('portrait');
                                    jQuery('.collections-wrapper').addClass('landscape');
                                    jQuery('#easyscroll').css({'height':'476'});
                            } else {
                                    thumbImgWidth = 56;
                                    jQuery('.collections-wrapper').removeClass('landscape');
                                    jQuery('.collections-wrapper').addClass('portrait');
                                    jQuery('#easyscroll').css({'height':'650'});
                            }

                            jQuery.each(data.images, function(i,images){
                               jQuery('#collections-slider #scrollthumbs').append('<a href="#"><img src="'+images+'" width="'+thumbImgWidth+'" /></a>');
                            });

                            //clear and re-populate large main image with first image in carousel
                            var setNewMainImg = jQuery('#collections-slider #scrollthumbs a').eq(0).children('img').attr('src');
                            jQuery('#collections-main-image img').hide().attr('src',setNewMainImg).fadeIn();

                            // add selected class to first thumbnail image
                            jQuery('#collections-slider #scrollthumbs a').eq(0).addClass('selected');

                            // bring scroller back to top
                            document.getElementById('scrollthumbs').style.top = "0px";

                            if (!(data.images.length < 5)) {jQuery('#collections-slider .buttons').fadeIn();} else { jQuery('#collections-slider .buttons').fadeOut(); };

                      },
                    dataType:'json'
            });
    });

    jQuery("#makeMeScrollable").queryLoader2();

    // vertical accordion press nav
			jQuery('#press_nav').dcAccordion({
			        eventType: 'click',
			        hoverDelay: 200,
			        speed: 'slow',
			        saveState: false,
			        autoExpand: true
			});
			
			//init overlays
			jQuery('.press-item a').colorbox({
				onOpen:function(){ 
					jQuery('#cboxClose').addClass('press-close-bttn');
					 }
			});
			
			//hide all press items except for the first section
			jQuery('.press-wrapper').children('div').hide();
			jQuery('.press-wrapper').children('div').eq(0).fadeIn();
			
			// hide all press items inside each section
			jQuery('.press-wrapper div div').hide();
			
			// get the first year in the first section in the left nav
			var topyear = jQuery('#press_nav > li > ul > li > a').html();
			
			//add active class to first nav
			jQuery('#press_nav > li > ul > li:first-child a').addClass('active');
			
			// show the first year items in the first section
			jQuery(".press-wrapper div:first-child div span.press-item-date:contains('"+topyear+"')").parent().fadeIn();
			
			//show and hide groups of press
			jQuery('#press_nav li ul li a').click(function(e){
				e.preventDefault();
				
				// get the section and year of press items to show
				var psection = jQuery(this).parent().parent().prev().attr('href');
				var pdate = jQuery(this).html();
				
				// hide it all
				jQuery('.press-wrapper div, .press-wrapper div div').hide();
				
				// fade in the section wrapping div
				jQuery(psection).fadeIn();
				
				// fade in only those items that contain the year referenced in nav and under the associated section
				jQuery(psection + " div span.press-item-date:contains('"+pdate+"')").parent().fadeIn();
			
			});

   //product image slides
   jQuery('.product-slideshow').cycle({
        timeout: 0,
        pager:  '.product-slideshow-nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return selector string for existing anchor
            return '.product-slideshow-nav li:eq(' + idx + ') a';
        }
    });
    // pretty radio buttons
    custRadioButtons();
    function custRadioButtons(){
        jQuery('.product-size-wrapper label input').hide();
        jQuery('.product-size-wrapper label input[type="radio"]').each(function(){
            if (jQuery(this).attr('disabled')) {
                jQuery(this).parent().addClass('disabled');
            }
        });
        jQuery('.product-size-wrapper label').click(function(){
            if (jQuery(this).hasClass('disabled')) {
                jQuery('#errorMsg').html('Sorry, this size unavailable');
            } else {
                jQuery('.product-size-wrapper label input[type="radio"]').attr('checked', false);
                jQuery(this).find('input[type="radio"]').attr('checked', true);
                jQuery('.product-size-wrapper label').removeClass('selected');
                jQuery(this).addClass('selected');
                jQuery('#errorMsg').html('');
            }
        });
    };

    // size chart
    jQuery(".size-chart").colorbox({
        inline:true, 
        href:"#sizeChart"
    });
   
    jQuery('.slideshow').cycle({
        fx: 'fade',				
        timeout:  4000,				
        next:   '#next',     			
        prev:   '#prev'
    });

    // Main Nav Dropdown
    function menuAnimateIn() {
        var ul = jQuery(this).children("ul");
        ul.animate({
            height: "show", 
            opacity: 1
        }, {
            duration: 220
        });

        jQuery(this).children("a").addClass('hovering');
    };

    function menuAnimateOut() {
        var ul = jQuery(this).children("ul");
        ul.animate({
            height: "hide", 
            opacity: 0,
            'margin-top':'5px'
        	}, {
            duration: 220
        });

        jQuery(this).children("a").removeClass('hovering');
    };

    jQuery("#main_nav ul li").hoverIntent({
        over: menuAnimateIn, 
        timeout: 100, 
        out: menuAnimateOut
    });
    
    /**
     * Mini Cart
     */
    if(typeof productAddToCartForm != "undefined") {
        productAddToCartForm.submit = function(obj, url) {
            if (this.validator.validate()) { 
                jQuery('#addtocart_error').css('display', 'none');
                jQuery('#ajaxloader').css('display', 'block');
                var button = jQuery(obj);
                button.attr('disabled', 'disabled');
                var form = jQuery('#product_addtocart_form');
                var formAction = form.attr('action');
                var data = {};
                jQuery('.super-attribute-select').each(function(i, item){
                    item = jQuery(item);
                    data[item.attr('name')] = item.val();
                });
                jQuery.post(formAction, data, function(response){
                    try {
                        var obj = jQuery.parseJSON(response);
                        
                        // Check qty
                        if(obj.error) {
                            jQuery('#addtocart_error').css('display', 'block');
                            button.removeAttr('disabled');
                            jQuery('#ajaxloader').css('display', 'none');
                        } else {
                        
                            var qty = parseInt(obj.qty);
                            var anchor = jQuery('#my_bag_bttn');
                            var anchorStr = qty > 0 ? 'my bag (' + qty + ' items)' : 'my bag';
                            anchor.text(anchorStr);
                            anchor.attr('title', anchorStr);

                            jQuery('#my_bag').remove();
                            jQuery(obj.html).appendTo(jQuery('#my_cart_li'));
                            jQuery('.open-my-bag').click();
                        }
                    } catch(e) { // <= That's an error
                        void(0);
                    }
                    
                    button.removeAttr('disabled');
                    jQuery('#ajaxloader').css('display', 'none');
                });
                
                
            }
            return false;
        }
    }
    
    
    // My bag drop-down function
    // show remove item button
    jQuery('#my_bag .my-bag-item').live('mouseenter', function(){
        jQuery(this).find('.remove-item').stop(true,true).fadeIn();
    }).live('mouseleave', function(){
        jQuery(this).find('.remove-item').stop(true,true).fadeOut();
    });
    
    
    // show my bag drop-down
    jQuery('.open-my-bag, .my-bag-close').live('click', function(event) {
        event.preventDefault();
        updateScroller();
        jQuery('#my_bag').fadeToggle("fast", "linear");
        updateScroller();
        return false;
    });
    
//    jQuery("#my_bag").mouseenter(function(){
//        jQuery(this).stop(true,true).fadeIn("fast", "linear");
//    }).mouseleave(function(){
//        jQuery(this).stop(true,true).delay(3000).fadeOut("fast", "linear");
//    });
    
    function initScroller(selector, sizethumb) {
        // if there is a scroller present, initialize it, get/set heights
        var scroller = jQuery(selector);
        if (scroller.length) { // implies *not* zero
            scroller.tinyscrollbar({
                sizethumb: sizethumb
            });
        }
        return scroller;
    }
    
    function updateScroller() {
        var oScrollbar = initScroller('#mybag_scrollbar1', 30);
        
        var vHeight = jQuery('.viewport').css('height').replace('px','');
        var totalHeight = jQuery('.overview').css('height').replace('px', '');
        
        if(totalHeight<262) {
            jQuery('.viewport').css("height", '206px' );
            oScrollbar.tinyscrollbar_update();
        } else {
            jQuery('.viewport').css("height", '262px' );
            oScrollbar.tinyscrollbar({
                sizethumb: 30
            });
            oScrollbar.tinyscrollbar_update();
        }
        
        //if there are no checkout items, don't allow the drop-down or
        // allow it to open and message the user
        if (!(jQuery('.my-bag-item').length)){
            jQuery('.viewport').css("height",120);
			
            // remove class to prevent it from opening
//            jQuery('#my_bag_bttn').removeClass('open-my-bag');
			
            //or comment out above and use below to just message user
            jQuery('.subtotal').html("<p>Your bag is empty.</p>");
            jQuery('#checkout_button').hide();
        }
        
    };
    
    
    // AJAX call to remove item from list
    jQuery('a.remove-item').live('click', function(event) {
        event.preventDefault();
    	
        if (confirm("Are you sure you want to delete this item?"))
        {
            var id = jQuery(this).parent().attr('id');
            var data = 'id=' + id ;
            var parent = jQuery(this).parent();

            jQuery.ajax(
            {
                type: "POST",
                data: data,
                url: jQuery(this).attr('href'),
                cache: false,	
                success: function(qty)
                {
                    var anchor = jQuery('#my_bag_bttn');
                    var anchorStr = qty > 0 ? 'my bag (' + qty + ' items)' : 'my bag';
                    anchor.text(anchorStr);
                    anchor.attr('title', anchorStr)
                    parent.fadeOut('fast', function() {
                        jQuery(this).siblings().remove();
                        jQuery(this).remove();
                        updateScroller(); 
								
                        if (!(jQuery('.my-bag-item').length)){
                            jQuery('#my_bag').hide();
                        }
                    });
							
                }
            });
        }
			
    });
    
    
    
    
    jQuery('.category-item').hover(function(){
        jQuery(this).find('.category-item-info').stop().animate({
            bottom: '0px'
        },250);
        jQuery(this).find('img').eq(0).stop(true,true).fadeOut('slow');
    },
    function(){
        jQuery(this).find('.category-item-info').stop().animate({
            bottom: '-76px',
            'margin-bottom': '2px'
        },500);
        jQuery(this).find('img').eq(0).stop(true,true).fadeIn('slow');
    });

    initScroller();
});



/**
* 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
*/
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, 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) } })(jQuery);

// magnify... zoom
//////////////////////////////////////////////////////////////////////////////////
// Cloud Zoom V1.0.2
// (c) 2010 by R Cecco. <http://www.professorcloud.com>
// MIT License
//
// Please retain this copyright header in all versions of the software
//////////////////////////////////////////////////////////////////////////////////
(function($){$(document).ready(function(){$('.cloud-zoom, .cloud-zoom-gallery').CloudZoom()});function format(str){for(var i=1;i<arguments.length;i++){str=str.replace('%'+(i-1),arguments[i])}return str}function CloudZoom(jWin,opts){var sImg=$('img',jWin);var img1;var img2;var zoomDiv=null;var $mouseTrap=null;var lens=null;var $tint=null;var softFocus=null;var $ie6Fix=null;var zoomImage;var controlTimer=0;var cw,ch;var destU=0;var destV=0;var currV=0;var currU=0;var filesLoaded=0;var mx,my;var ctx=this,zw;setTimeout(function(){if($mouseTrap===null){var w=jWin.width();jWin.parent().append(format('<div style="width:%0px;position:absolute;top:10%;left:2%;text-align:center" class="cloud-zoom-loading" >Zoom Image Loading...</div>',w/3,(w/2)-(w/6))).find(':last').css('opacity',0.5)}},200);var ie6FixRemove=function(){if($ie6Fix!==null){$ie6Fix.remove();$ie6Fix=null}};this.removeBits=function(){if(lens){lens.remove();lens=null}if($tint){$tint.remove();$tint=null}if(softFocus){softFocus.remove();softFocus=null}ie6FixRemove();$('.cloud-zoom-loading',jWin.parent()).remove()};this.destroy=function(){jWin.data('zoom',null);if($mouseTrap){$mouseTrap.unbind();$mouseTrap.remove();$mouseTrap=null}if(zoomDiv){zoomDiv.remove();zoomDiv=null}this.removeBits()};this.fadedOut=function(){if(zoomDiv){zoomDiv.remove();zoomDiv=null}this.removeBits()};this.controlLoop=function(){if(lens){var x=(mx-sImg.offset().left-(cw*0.5))>>0;var y=(my-sImg.offset().top-(ch*0.5))>>0;if(x<0){x=0}else if(x>(sImg.outerWidth()-cw)){x=(sImg.outerWidth()-cw)}if(y<0){y=0}else if(y>(sImg.outerHeight()-ch)){y=(sImg.outerHeight()-ch)}lens.css({left:x,top:y});lens.css('background-position',(-x)+'px '+(-y)+'px');destU=(((x)/sImg.outerWidth())*zoomImage.width)>>0;destV=(((y)/sImg.outerHeight())*zoomImage.height)>>0;currU+=(destU-currU)/opts.smoothMove;currV+=(destV-currV)/opts.smoothMove;zoomDiv.css('background-position',(-(currU>>0)+'px ')+(-(currV>>0)+'px'))}controlTimer=setTimeout(function(){ctx.controlLoop()},30)};this.init2=function(img,id){filesLoaded++;if(id===1){zoomImage=img}if(filesLoaded===2){this.init()}};this.init=function(){$('.cloud-zoom-loading',jWin.parent()).remove();$mouseTrap=jWin.parent().append(format("<div class='mousetrap' style='background-image:url(\".\");z-index:999;position:absolute;width:%0px;height:%1px;left:%2px;top:%3px;\'></div>",sImg.outerWidth(),sImg.outerHeight(),0,0)).find(':last');$mouseTrap.bind('mousemove',this,function(event){mx=event.pageX;my=event.pageY});$mouseTrap.bind('mouseleave',this,function(event){clearTimeout(controlTimer);if(lens){lens.fadeOut(299)}if($tint){$tint.fadeOut(299)}if(softFocus){softFocus.fadeOut(299)}zoomDiv.fadeOut(300,function(){ctx.fadedOut()});return false});$mouseTrap.bind('mouseenter',this,function(event){mx=event.pageX;my=event.pageY;zw=event.data;if(zoomDiv){zoomDiv.stop(true,false);zoomDiv.remove()}var xPos=opts.adjustX,yPos=opts.adjustY;var siw=sImg.outerWidth();var sih=sImg.outerHeight();var w=opts.zoomWidth;var h=opts.zoomHeight;if(opts.zoomWidth=='auto'){w=siw}if(opts.zoomHeight=='auto'){h=sih}var appendTo=jWin.parent();switch(opts.position){case'top':yPos-=h;break;case'right':xPos+=siw;break;case'bottom':yPos+=sih;break;case'left':xPos-=w;break;case'inside':w=siw;h=sih;break;default:appendTo=$('#'+opts.position);if(!appendTo.length){appendTo=jWin;xPos+=siw;yPos+=sih}else{w=appendTo.innerWidth();h=appendTo.innerHeight()}}zoomDiv=appendTo.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:%2px;height:%3px;background-image:url(\'%4\');z-index:99;"></div>',xPos,yPos,w,h,zoomImage.src)).find(':last');if(sImg.attr('title')&&opts.showTitle){zoomDiv.append(format('<div class="cloud-zoom-title">%0</div>',sImg.attr('title'))).find(':last').css('opacity',opts.titleOpacity)}if($.browser.msie&&$.browser.version<7){$ie6Fix=$('<iframe frameborder="0" src="#"></iframe>').css({position:"absolute",left:xPos,top:yPos,zIndex:99,width:w,height:h}).insertBefore(zoomDiv)}zoomDiv.fadeIn(500);if(lens){lens.remove();lens=null}cw=(sImg.outerWidth()/zoomImage.width)*zoomDiv.width();ch=(sImg.outerHeight()/zoomImage.height)*zoomDiv.height();lens=jWin.append(format("<div class = 'cloud-zoom-lens' style='display:none;z-index:98;position:absolute;width:%0px;height:%1px;'></div>",cw,ch)).find(':last');$mouseTrap.css('cursor',lens.css('cursor'));var noTrans=false;if(opts.tint){lens.css('background','url("'+sImg.attr('src')+'")');$tint=jWin.append(format('<div style="display:none;position:absolute; left:0px; top:0px; width:%0px; height:%1px; background-color:%2;" />',sImg.outerWidth(),sImg.outerHeight(),opts.tint)).find(':last');$tint.css('opacity',opts.tintOpacity);noTrans=true;$tint.fadeIn(500)}if(opts.softFocus){lens.css('background','url("'+sImg.attr('src')+'")');softFocus=jWin.append(format('<div style="position:absolute;display:none;top:2px; left:2px; width:%0px; height:%1px;" />',sImg.outerWidth()-2,sImg.outerHeight()-2,opts.tint)).find(':last');softFocus.css('background','url("'+sImg.attr('src')+'")');softFocus.css('opacity',0.5);noTrans=true;softFocus.fadeIn(500)}if(!noTrans){lens.css('opacity',opts.lensOpacity)}if(opts.position!=='inside'){lens.fadeIn(500)}zw.controlLoop();return})};img1=new Image();$(img1).load(function(){ctx.init2(this,0)});img1.src=sImg.attr('src');img2=new Image();$(img2).load(function(){ctx.init2(this,1)});img2.src=jWin.attr('href')}$.fn.CloudZoom=function(options){try{document.execCommand("BackgroundImageCache",false,true)}catch(e){}this.each(function(){var relOpts,opts;eval('var   a = {'+$(this).attr('rel')+'}');relOpts=a;if($(this).is('.cloud-zoom')){$(this).css({'position':'relative','display':'block'});$('img',$(this)).css({'display':'block'});if($(this).parent().attr('id')!='wrap'){$(this).wrap('<div id="wrap" style="top:0px;z-index:9999;position:relative;"></div>')}opts=$.extend({},$.fn.CloudZoom.defaults,options);opts=$.extend({},opts,relOpts);$(this).data('zoom',new CloudZoom($(this),opts))}else if($(this).is('.cloud-zoom-gallery')){opts=$.extend({},relOpts,options);$(this).data('relOpts',opts);$(this).bind('click',$(this),function(event){var data=event.data.data('relOpts');$('#'+data.useZoom).data('zoom').destroy();$('#'+data.useZoom).attr('href',event.data.attr('href'));$('#'+data.useZoom+' img').attr('src',event.data.data('relOpts').smallImage);$('#'+event.data.data('relOpts').useZoom).CloudZoom();return false})}});return this};$.fn.CloudZoom.defaults={zoomWidth:'auto',zoomHeight:'auto',position:'right',tint:false,tintOpacity:0.5,lensOpacity:0.5,softFocus:false,smoothMove:3,showTitle:true,titleOpacity:0.5,adjustX:0,adjustY:0}})(jQuery);

//vertical accordion nav
(function($){$.fn.dcAccordion=function(options){var defaults={classParent:'dcjq-parent',classActive:'active',classArrow:'dcjq-icon',classCount:'dcjq-count',classExpand:'dcjq-current-parent',eventType:'click',hoverDelay:300,menuClose:true,autoClose:true,autoExpand:false,speed:'slow',saveState:true,disableLink:true,showCount:false,cookie:'dcjq-accordion'};var options=$.extend(defaults,options);this.each(function(options){var obj=this;setUpAccordion();if(defaults.saveState==true){checkCookie(defaults.cookie,obj)}if(defaults.autoExpand==true){$('li.'+defaults.classExpand+' > a').addClass(defaults.classActive)}resetAccordion();if(defaults.eventType=='hover'){var config={sensitivity:2,interval:defaults.hoverDelay,over:linkOver,timeout:defaults.hoverDelay,out:linkOut};$('li a',obj).hoverIntent(config);var configMenu={sensitivity:2,interval:1000,over:menuOver,timeout:1000,out:menuOut};$(obj).hoverIntent(configMenu);if(defaults.disableLink==true){$('li a',obj).click(function(e){if($(this).siblings('ul').length>0){e.preventDefault()}})}}else{$('li a',obj).click(function(e){$activeLi=$(this).parent('li');$parentsLi=$activeLi.parents('li');$parentsUl=$activeLi.parents('ul');if(defaults.disableLink==true){if($(this).siblings('ul').length>0){e.preventDefault()}}if(defaults.autoClose==true){autoCloseAccordion($parentsLi,$parentsUl)}if($('> ul',$activeLi).is(':visible')){$('ul',$activeLi).slideUp(defaults.speed);$('a',$activeLi).removeClass(defaults.classActive)}else{$(this).siblings('ul').slideToggle(defaults.speed);$('> a',$activeLi).addClass(defaults.classActive)}if(defaults.saveState==true){createCookie(defaults.cookie,obj)}})}function setUpAccordion(){$arrow='<span class="'+defaults.classArrow+'"></span>';var classParentLi=defaults.classParent+'-li';$('> ul',obj).show();$('li',obj).each(function(){if($('> ul',this).length>0){$(this).addClass(classParentLi);$('> a',this).addClass(defaults.classParent).append($arrow)}});$('> ul',obj).hide();if(defaults.showCount==true){$('li.'+classParentLi,obj).each(function(){if(defaults.disableLink==true){var getCount=parseInt($('ul a:not(.'+defaults.classParent+')',this).length)}else{var getCount=parseInt($('ul a',this).length)}$('> a',this).append(' <span class="'+defaults.classCount+'">('+getCount+')</span>')})}}function linkOver(){$activeLi=$(this).parent('li');$parentsLi=$activeLi.parents('li');$parentsUl=$activeLi.parents('ul');if(defaults.autoClose==true){autoCloseAccordion($parentsLi,$parentsUl)}if($('> ul',$activeLi).is(':visible')){$('ul',$activeLi).slideUp(defaults.speed);$('a',$activeLi).removeClass(defaults.classActive)}else{$(this).siblings('ul').slideToggle(defaults.speed);$('> a',$activeLi).addClass(defaults.classActive)}if(defaults.saveState==true){createCookie(defaults.cookie,obj)}}function linkOut(){}function menuOver(){}function menuOut(){if(defaults.menuClose==true){$('ul',obj).slideUp(defaults.speed);$('a',obj).removeClass(defaults.classActive);createCookie(defaults.cookie,obj)}}function autoCloseAccordion($parentsLi,$parentsUl){$('ul',obj).not($parentsUl).slideUp(defaults.speed);$('a',obj).removeClass(defaults.classActive);$('> a',$parentsLi).addClass(defaults.classActive)}function resetAccordion(){$('ul',obj).hide();$allActiveLi=$('a.'+defaults.classActive,obj);$allActiveLi.siblings('ul').show()}});function checkCookie(cookieId,obj){var cookieVal=$.cookie(cookieId);if(cookieVal!=null){var activeArray=cookieVal.split(',');$.each(activeArray,function(index,value){var $cookieLi=$('li:eq('+value+')',obj);$('> a',$cookieLi).addClass(defaults.classActive);var $parentsLi=$cookieLi.parents('li');$('> a',$parentsLi).addClass(defaults.classActive)})}}function createCookie(cookieId,obj){var activeIndex=[];$('li a.'+defaults.classActive,obj).each(function(i){var $arrayItem=$(this).parent('li');var itemIndex=$('li',obj).index($arrayItem);activeIndex.push(itemIndex)});$.cookie(cookieId,activeIndex,{path:'/'})}}})(jQuery);

//tiny scroller
(function($){$.tiny=$.tiny||{};$.tiny.scrollbar={options:{axis:'y',wheel:40,scroll:true,size:'auto',sizethumb:'auto'}};$.fn.tinyscrollbar=function(options){var options=$.extend({},$.tiny.scrollbar.options,options);this.each(function(){$(this).data('tsb',new Scrollbar($(this),options));});return this;};$.fn.tinyscrollbar_update=function(sScroll){return $(this).data('tsb').update(sScroll);};function Scrollbar(root,options){var oSelf=this;var oWrapper=root;var oViewport={obj:$('.viewport',root)};var oContent={obj:$('.overview',root)};var oScrollbar={obj:$('.scrollbar',root)};var oTrack={obj:$('.track',oScrollbar.obj)};var oThumb={obj:$('.thumb',oScrollbar.obj)};var sAxis=options.axis=='x',sDirection=sAxis?'left':'top',sSize=sAxis?'Width':'Height';var iScroll,iPosition={start:0,now:0},iMouse={};function initialize(){oSelf.update();setEvents();return oSelf;}
this.update=function(sScroll){oViewport[options.axis]=oViewport.obj[0]['offset'+sSize];oContent[options.axis]=oContent.obj[0]['scroll'+sSize];oContent.ratio=oViewport[options.axis]/oContent[options.axis];oScrollbar.obj.toggleClass('disable',oContent.ratio>=1);oTrack[options.axis]=options.size=='auto'?oViewport[options.axis]:options.size;oThumb[options.axis]=Math.min(oTrack[options.axis],Math.max(0,(options.sizethumb=='auto'?(oTrack[options.axis]*oContent.ratio):options.sizethumb)));oScrollbar.ratio=options.sizethumb=='auto'?(oContent[options.axis]/oTrack[options.axis]):(oContent[options.axis]-oViewport[options.axis])/(oTrack[options.axis]-oThumb[options.axis]);iScroll=(sScroll=='relative'&&oContent.ratio<=1)?Math.min((oContent[options.axis]-oViewport[options.axis]),Math.max(0,iScroll)):0;iScroll=(sScroll=='bottom'&&oContent.ratio<=1)?(oContent[options.axis]-oViewport[options.axis]):isNaN(parseInt(sScroll))?iScroll:parseInt(sScroll);setSize();};function setSize(){oThumb.obj.css(sDirection,iScroll/oScrollbar.ratio);oContent.obj.css(sDirection,-iScroll);iMouse['start']=oThumb.obj.offset()[sDirection];var sCssSize=sSize.toLowerCase();oScrollbar.obj.css(sCssSize,oTrack[options.axis]);oTrack.obj.css(sCssSize,oTrack[options.axis]);oThumb.obj.css(sCssSize,oThumb[options.axis]);};function setEvents(){oThumb.obj.bind('mousedown',start);oThumb.obj[0].ontouchstart=function(oEvent){oEvent.preventDefault();oThumb.obj.unbind('mousedown');start(oEvent.touches[0]);return false;};oTrack.obj.bind('mouseup',drag);if(options.scroll&&this.addEventListener){oWrapper[0].addEventListener('DOMMouseScroll',wheel,false);oWrapper[0].addEventListener('mousewheel',wheel,false);}
else if(options.scroll){oWrapper[0].onmousewheel=wheel;}};function start(oEvent){iMouse.start=sAxis?oEvent.pageX:oEvent.pageY;var oThumbDir=parseInt(oThumb.obj.css(sDirection));iPosition.start=oThumbDir=='auto'?0:oThumbDir;$(document).bind('mousemove',drag);document.ontouchmove=function(oEvent){$(document).unbind('mousemove');drag(oEvent.touches[0]);};$(document).bind('mouseup',end);oThumb.obj.bind('mouseup',end);oThumb.obj[0].ontouchend=document.ontouchend=function(oEvent){$(document).unbind('mouseup');oThumb.obj.unbind('mouseup');end(oEvent.touches[0]);};return false;};function wheel(oEvent){if(!(oContent.ratio>=1)){oEvent=$.event.fix(oEvent||window.event);var iDelta=oEvent.wheelDelta?oEvent.wheelDelta/120:-oEvent.detail/3;iScroll-=iDelta*options.wheel;iScroll=Math.min((oContent[options.axis]-oViewport[options.axis]),Math.max(0,iScroll));oThumb.obj.css(sDirection,iScroll/oScrollbar.ratio);oContent.obj.css(sDirection,-iScroll);oEvent.preventDefault();};};function end(oEvent){$(document).unbind('mousemove',drag);$(document).unbind('mouseup',end);oThumb.obj.unbind('mouseup',end);document.ontouchmove=oThumb.obj[0].ontouchend=document.ontouchend=null;return false;};function drag(oEvent){if(!(oContent.ratio>=1)){iPosition.now=Math.min((oTrack[options.axis]-oThumb[options.axis]),Math.max(0,(iPosition.start+((sAxis?oEvent.pageX:oEvent.pageY)-iMouse.start))));iScroll=iPosition.now*oScrollbar.ratio;oContent.obj.css(sDirection,-iScroll);oThumb.obj.css(sDirection,iPosition.now);}
return false;};return initialize();};})(jQuery);

// tiny carousel
(function($){$.tiny=$.tiny||{};$.tiny.carousel={options:{start:1,display:1,axis:'x',controls:true,pager:false,interval:false,intervaltime:3000,rewind:false,animation:true,duration:1000,callback:null}};$.fn.tinycarousel=function(options){var options=$.extend({},$.tiny.carousel.options,options);this.each(function(){$(this).data('tcl',new Carousel($(this),options));});return this;};$.fn.tinycarousel_start=function(){$(this).data('tcl').start();};$.fn.tinycarousel_stop=function(){$(this).data('tcl').stop();};$.fn.tinycarousel_move=function(iNum){$(this).data('tcl').move(iNum-1,true);};function Carousel(root,options){var oSelf=this;var oViewport=$('.viewport:first',root);var oContent=$('.overview:first',root);var oPages=oContent.children();var oBtnNext=$('.next:first',root);var oBtnPrev=$('.prev:first',root);var oPager=$('.pager:first',root);var iPageSize,iSteps,iCurrent,oTimer,bPause,bForward=true,bAxis=options.axis=='x';function initialize(){iPageSize=bAxis?$(oPages[0]).outerWidth(true):$(oPages[0]).outerHeight(true);var iLeftover=Math.ceil(((bAxis?oViewport.outerWidth():oViewport.outerHeight())/(iPageSize*options.display))-1);iSteps=Math.max(1,Math.ceil(oPages.length/options.display)-iLeftover);iCurrent=Math.min(iSteps,Math.max(1,options.start))-2;oContent.css(bAxis?'width':'height',(iPageSize*oPages.length));oSelf.move(1);setEvents();return oSelf;};function setEvents(){if(options.controls&&oBtnPrev.length>0&&oBtnNext.length>0){oBtnPrev.click(function(){oSelf.move(-1);return false;});oBtnNext.click(function(){oSelf.move(1);return false;});}if(options.interval){root.hover(oSelf.stop,oSelf.start);}if(options.pager&&oPager.length>0){$('a',oPager).click(setPager);}};function setButtons(){if(options.controls){oBtnPrev.toggleClass('disable',!(iCurrent>0));oBtnNext.toggleClass('disable',!(iCurrent+1<iSteps));}if(options.pager){var oNumbers=$('.pagenum',oPager);oNumbers.removeClass('active');$(oNumbers[iCurrent]).addClass('active');}};function setPager(oEvent){if($(this).hasClass('pagenum')){oSelf.move(parseInt(this.rel),true);}return false;};function setTimer(){if(options.interval&&!bPause){clearTimeout(oTimer);oTimer=setTimeout(function(){iCurrent=iCurrent+1==iSteps?-1:iCurrent;bForward=iCurrent+1==iSteps?false:iCurrent==0?true:bForward;oSelf.move(bForward?1:-1);},options.intervaltime);}};this.stop=function(){clearTimeout(oTimer);bPause=true;};this.start=function(){bPause=false;setTimer();};this.move=function(iDirection,bPublic){iCurrent=bPublic?iDirection:iCurrent+=iDirection;if(iCurrent>-1&&iCurrent<iSteps){var oPosition={};oPosition[bAxis?'left':'top']=-(iCurrent*(iPageSize*options.display));oContent.animate(oPosition,{queue:false,duration:options.animation?options.duration:0,complete:function(){if(typeof options.callback=='function')options.callback.call(this,oPages[iCurrent],iCurrent);}});setButtons();setTimer();}};return initialize();};})(jQuery);

// cookie
jQuery.cookie=function(a,b,c){if(arguments.length>1&&String(b)!=="[object Object]"){c=jQuery.extend({},c);if(b===null||b===undefined){c.expires=-1}if(typeof c.expires==="number"){var d=c.expires,e=c.expires=new Date;e.setDate(e.getDate()+d)}b=String(b);return document.cookie=[encodeURIComponent(a),"=",c.raw?b:encodeURIComponent(b),c.expires?"; expires="+c.expires.toUTCString():"",c.path?"; path="+c.path:"",c.domain?"; domain="+c.domain:"",c.secure?"; secure":""].join("")}c=b||{};var f,g=c.raw?function(a){return a}:decodeURIComponent;return(f=(new RegExp("(?:^|; )"+encodeURIComponent(a)+"=([^;]*)")).exec(document.cookie))?g(f[1]):null}
