//$('#thumb').hide();

	var filename=null;
        		function xtractFile(data){
     		       var m = data.replace(/#.*/,"").match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
			if(m==null){
				var x=data.substring(0, (data.indexOf("?") == -1) ? data.length : data.indexOf("?"));
				x=x.substring(x.lastIndexOf("/") + 1, x.length);
			}
     		       m=(m==null?new Array("",data,x):m);
  		     // alert(""+m[1]+"<br/><br/>"+m[2]+"<br/>");
      		       return {file: m[2],path:m[1],dat:data}
        		}
 	function autoTab(link) {
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li").removeClass("active"); //Remove any "active" class

		var gotab=$("ul.tabs li a[rel='"+link+"']");
		var goindex=parseInt(gotab.parent().parent().parent().index()); //.attr("class"));
				// alert($('#fader li').length+' '+goindex);
		$('#fader').cycle(goindex); //{fx:'wipe',speed:250,timeout:0,startingSlide:goindex});
		gotab.parent().parent().parent().addClass("active").show();
		$(link).customFadeIn(300); 
		$('html').removeClass().addClass($("ul.tabs li.active").attr("class"));
	}

(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);
		/* custom functions to toggle the glass panels on and off */
		$.fn.fadeToggle = function(speed, easing, callback) {
   			return this.animate({opacity: 'toggle'}, speed, easing, callback);
		}; 
		$(function() {
		        $("#lucency").click(function () {
			var str=$(".lucent").is(':visible')?
			        "Show content<img src=\"images/show.png\" />":
			        "Show background<img src=\"images/hide.png\" />";
		//	if($(".lucent").is(':visible')){$('#fader').cycle({timeout:3000});} else {$('#fader').cycle({timeout:0}); }
		                  $("#lucency").html(str);
		                  $(".lucent").fadeToggle();
		        }); 
		});
		$(function() {
		        $(".rightnav h4").css('cursor','pointer').click(function () {
			var str=$("div#inright").is(':visible')?
			        "MENU<img src=\"images/show.png\" />":
			        "MENU<img src=\"images/hide.png\" />";
		                  $(".rightnav h4").html(str);
		                $("div#inright").fadeToggle('slow','swing');
		        }); 
		});


		function initMenu() {
  	   		$('#menu').hide();
  	   		$('#menu ul').hide();
  	   		$('#menu').fadeIn('slow');
		
			filename=xtractFile(window.location.href).file;
			var link=$("#menu li a[href='"+filename+"']");
			$('#menu li a').removeClass("active");
			link.addClass('active');

			var child=link.next();
	     		var hasSubMenu = child.is('ul');
			var parent=link.parent().parent();
			var isTopLevel=parent.is('ul#menu'); 
			if (hasSubMenu) { child.slideDown('normal'); return;}
			if (!isTopLevel) {  parent.slideDown('normal'); return;}
	   	$('#menu li a').click(
	   	       function() {
			return true;
	      	        });

		
	  	}

    var eventNumber = 1; //so we can track the ordering of the events in the example 
    $(function(){ 
     		//alert($('.slide-wrapper').length);

      $('.lucent').hide();

    if($('.slide-wrapper').length==0 || xtractFile(location.href).file=="accessories2.html") {
       $('.loading').hide();
       $('.lucent').fadeIn('slow');
       return;
    }

        // IF it's 'file:', use call the allCycled cycle wrapper function - any missing images will stop onImageLoad
	/*
	if(/^file:/i.test(xtractFile(location.href).path)) {
		var cyc=allCycled($('.slide-wrapper'));
		$('.slide-wrapper').fadeIn('slow'); 
	         //$('#dbug').html(c);
	}
	return;
	*/
        $('.slide-wrapper img').onImagesLoad({ 
             itemCallback: itemImagesLoaded, 
             selectorCallback: selectorImagesLoaded 
        }); 
        // itemImagesLoaded (the itemCallback) is invoked once for each item that $('.slide-wrapper img') encapsulates 
        function itemImagesLoaded(domObject){ 
              //     $('#dbug').append('<div class="loaded" style="color:blue;text-align:left">Event #'+(eventNumber++)+': Image ' + displayTxt(domObject) +
              //     ' has loaded. Displayed dimensions: ' +domObject.width + 'x' + domObject.height + '</div>');
        } 
        //selectorImagesLoaded (the selectorCallback) is invoked only once: when all images that $('.slide-wrapper') encapsulates have loaded 
        function selectorImagesLoaded($selector){ 
               /*    var allLoaded = ""; //build a string of all items within the selector 
            	$selector.each(function(){ 
            	    allLoaded  = displayTxt(this) + ', '; 
            	}) 
                   $('.tabcontainer').prepend('<div class="loaded" style="color:#444;">Event #'+(eventNumber++)+': the images have loaded within selector $(&quot;' + $selector.selector + '&quot;), which contains the following ' + $selector.length + ' items: ' + allLoaded + '</div>'); 
	*/
	 var cyc=allCycled(this.parent().parent());
                    $('.loading').hide();
 	 $('.lucent').fadeIn('slow'); 
        } 
        function displayTxt(domObject){ //helper function for displaying results 
	var f=(domObject.tagName=="IMG"?xtractFile(domObject.src).file:"")
            	return '&lt;' + f + (domObject.className? ' class=&quot;' + domObject.className + '&quot;' : '') + '&gt;'; 
        } 

    }); 

     function allCycled(sel) {
            sel.each(function(){ 
	var s="";
		         var slide = $('.slide',this), 
		         caption = $('.slidecaption',this),
		         nav = $('<ul class="nav"></ul>').insertBefore(caption);

		         slide.cycle({   
			fx:     'toss',
			speed:  'slow', 
			timeout: 0, 
			width: 390,
			height: 'auto',
			pager:   nav,
			before: function() {
				caption.html('<p>&nbsp;</p>').css('height','16px');
			},
			after:  function() {
				caption.html(this.alt).css('height','auto');
			},
			pagerAnchorBuilder: function(idx, slide) { 
			         s+=slide.complete+" "+slide.width+" "+slide.height+" "+unescape(xtractFile(slide.src).file)+"<br/>";
   			         return '<li><a href="#"><img src="' + slide.src + '" width="50" height="40" /></a></li>'; 
			} 
		        })
		 
            }) 
   //    $('.loading').hide();

     };

		$(function() {
   			$('#fader').cycle({
				fx: 'wipe', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				speed: 250,
				timeout:0, //12000,
				cleartype: 1,
				delay:-250
			});

			/* tabs */

			$(".tab_content").hide(); //Hide all content

			if(window.location.search) {

				var hash=window.location.search;
				hash=hash.replace(/^\?/,"#");
				var gotab=$("ul.tabs li a[rel='"+hash+"']");
				var goindex=parseInt(gotab.parent().parent().parent().index()); //.attr("class"));
				// alert($('#fader li').length+' '+goindex);
				$('#fader').cycle(goindex); //{fx:'wipe',speed:250,timeout:0,startingSlide:goindex});
				gotab.parent().parent().parent().addClass("active").show();
				$(hash).customFadeIn(300); 
			} else {
	 			$("ul.tabs li:not('.breakout'):first-child").addClass("active").show(); //Activate first tab with anchor
	 			$(".tab_content:first").fadeIn('slow'); //Show first tab content
			}
			$('html').removeClass().addClass($("ul.tabs li.active").attr("class"));

			        	//On Tab Click Event
				$("ul.tabs li").click(function() {
			      		$(window).scrollTop(0);
					$('html').removeClass().addClass($(this).attr("class"));
				/* ***** .index() REQUIRES 1.4 plus **** */
					var tabindex=parseInt($(this).index());

					$('#fader').cycle(tabindex);
					$("ul.tabs li").removeClass("active"); //Remove any "active" class
					$(".tab_content").hide(); //Hide all tab content
					var activeTab = $(this).find("a").attr("rel"); //Find the rel attribute value to identify the active tab + content
					$("ul.tabs li a[rel='"+activeTab+"']").parent().parent().parent().addClass("active");
					$(activeTab).customFadeIn(300); //Fade in the active content
				return false;
				});

		});

		$(function() {
			$('#expand').click(function() {
			        // Firefox bug - initially shows cart with length 19 even when empty
			});

		});
	$(function() {
		$(".draggable").draggable({handle:$('#draghandle'),containment:$('#wrapper')});  // ,containment:$('#wrapper')
	});


		$(document).ready(function() {


   		$("#expand").click(function () {
      			$(this).parent().hide();
      			/*$("#extra").fadeIn("slow", function () {
	      		});*/
			$("#extra").show(1000);

    		});
    		$("#contract").click(function () {
      			$("#extra").hide(1000, function () {
				$("#expand").parent().fadeIn('slow');
			});
    		});
      		$("#expand").parent().hide();
      		$("#extra").fadeIn("slow", function () {
	      		});

			initMenu();
	 //        	$('#audioContainer').show();
		if($('.slide-wrapper').length==0) {
       			$('.loading').hide();
       	 		$('.lucent').fadeIn('slow'); 

		};		
		
	         });  // end document.ready

