var numSteps = 0;
var steps = 0;
var stepWidth = 0;
var slideWidth = 0;
var currentPod = 0;

jQuery(function(){ // start jQuery
	numSteps = jQuery(".mainColumnLrgWrap .mainColumnLrg").length;
	steps = jQuery(".mainColumnLrgWrap .mainColumnLrg");
	stepWidth = jQuery(".mainColumnLrgWrap .mainColumnLrg").width();
	slideWidth = numSteps * stepWidth;
	currentPod = 0;
		
	// SHOPPING TABLE FORMATING	
	jQuery(".twoColTable tr td:nth-child(2), .twoColTable tr th:nth-child(2)").addClass("textRight");
	jQuery(".bgTan .hashTable tbody tr:nth-child(even)").addClass("alt");
	jQuery(".cart-table tbody tr:nth-child(even)").addClass("alt");
	jQuery(".bgWhite .hashTable tbody tr:nth-child(even)").addClass("alt");
	jQuery(".threeColTable tr th:nth-child(2), .threeColTable tr th:nth-child(3), .threeColTable tr td:nth-child(2), .threeColTable tr td:nth-child(3)").css({"width" : "15%" , "text-align" : "center"});
	//jQuery(".threeColTable tr th:nth-child(2) h4, .threeColTable tr th:nth-child(3) h4").css({"text-align" : "center"});
		
	// Slide Select
	jQuery(".slideWrap").css({width: slideWidth});
	
	jQuery(".slideNext").click(function(){
		jQuery(steps[currentPod]).fadeTo(250, 0);
		currentPod += 1;
		jQuery(steps[currentPod]).fadeTo(250, 1);
		jQuery(".slideWrap").animate({marginLeft : (stepWidth * -(currentPod))}, 500);
		
		indicate();
	});
	jQuery(".slidePrev").click(function(){
		jQuery(steps[currentPod]).fadeTo(250, 0);
		currentPod -= 1;
		jQuery(steps[currentPod]).fadeTo(250, 1);
		jQuery(".slideWrap").animate({marginLeft : (stepWidth * -(currentPod))}, 500);
		
		indicate();
	});
	
	jQuery("#template04 .byoNav a").click(function(){
		var newPod = jQuery("#template04 .byoNav a").index(jQuery(this)) - 1;
		if(newPod != currentPod && newPod > -1){
			jQuery(steps[currentPod]).fadeTo(250, 0);
			currentPod = newPod;
			jQuery(steps[currentPod]).fadeTo(250, 1);
			jQuery(".slideWrap").animate({marginLeft : (stepWidth * -(currentPod))}, 500);
			indicate();
		}
	});
	
	
	if(jQuery("#step02").hasClass("active")){
		jQuery("#subHeader2 table tr").hide();
		jQuery(".byoHead02").show(); 
	}
	
	// compare module
	//var theads = jQuery("#compareTable .thead dd");
//	var tbodys = jQuery("#compareTable .tbody dd");
//	var numThead = theads.length;
//	var numTbody = tbodys.length;
//	var x = 0;
//	
//	for (x=0; x<=2; x++){
//		var heightTbody = tbodys[x].height();
//		alert(heightTbody);
	//code to be executed
	
	//}
	
	jQuery(".compareShowDetails").click(function(){
		// set compare details to opacity 0
		jQuery(".compareDetails").css({visibility: "visible", opacity:"0"})
		jQuery("#compareTable dl").removeClass("on");
		// find what choice was clicked and get class
		var whatsOn = jQuery(this).parent().parent().attr("id");
		//
		var whatsOnID = "#" + whatsOn;
		// add "on" class
		jQuery(whatsOnID).addClass("on");
		// slide animation
		
		
		// hide other choices not "on"
		jQuery("#choice-01, #choice-02, #choice-03").not(".on").fadeTo(200, 0.0, function () {
			// show details
			if(jQuery("#choice-01").hasClass("on")){
				jQuery(whatsOnID).animate({marginLeft:"0px"}, 250, function(){
					jQuery(whatsOnID).next().css({display:"block"}).fadeTo(250, 1);
				});
			} else if (jQuery("#choice-02").hasClass("on")){
				jQuery(whatsOnID).animate({marginLeft:"-171px"}, 500, function(){
					jQuery(whatsOnID).next().css({display:"block"}).fadeTo(250, 1);
				});
			} else if (jQuery("#choice-03").hasClass("on")){
				jQuery(whatsOnID).animate({marginLeft:"-342px"}, 600, function(){
					jQuery(whatsOnID).next().css({display:"block"}).fadeTo(250, 1);
				});
			}
			jQuery(this).css({display:"none"});
			//jQuery(".compareDetails").fadeTo(250, 1);
		});
		// hide details button
		jQuery(this).css({display:"none"});
		jQuery(this).next().css({display:"block"});
		return false;
	});
	
	jQuery(".compareBack").click(function(){
		jQuery(".compareDetails").fadeTo(150, 0.0);
		// hide details button
		jQuery(this).css({display:"none"});
		jQuery(this).prev().css({display:"block"});
		var whatsOn = jQuery(this).parent().parent().attr("id");
		var whatsOnID = "#" + whatsOn;
		if(jQuery("#choice-01").hasClass("on")){
			jQuery(whatsOnID).animate({marginLeft:"0px"}, 200, function(){
				jQuery("#choice-01, #choice-02, #choice-03").not(".on").css({display:"block"}).fadeTo(250, 1);
			});
		} else if (jQuery("#choice-02").hasClass("on")){
			jQuery(whatsOnID).animate({marginLeft:"0"}, 400, function(){
				jQuery("#choice-01, #choice-02, #choice-03").not(".on").css({display:"block"}).fadeTo(250, 1);
			});
		} else if (jQuery("#choice-03").hasClass("on")){
			jQuery(whatsOnID).animate({marginLeft:"0"}, 500, function(){
				jQuery("#choice-01, #choice-02, #choice-03").not(".on").css({display:"block"}).fadeTo(250, 1);
			});
		}
		return false;
	});
	jQuery("#cboxClose").click(function(){
		jQuery("#choice-01, #choice-02, #choice-03").css({display:"block", marginLeft:"0", opacity:1});
		jQuery(".compareDetails").css({visibility: "visible", opacity:"0"})
	});
	
	// Tip Bubble
//	jQuery(".tip").each(function(){
//		var getTitle = jQuery(this).parent().parent().find("strong").text();
//		var getTitleFormat = "<h5>" + getTitle + "</h5>";
//		jQuery(this).find(".padding").prepend(getTitleFormat);
//	});
	
	jQuery(".question").hover(function(){
			var bubble = jQuery(this).find(".bubble");
			var getWidthTip = jQuery(this).width() + 10;
			//var getHeightBubble = ((bubble.height()) / 2 ) * -1;
			bubble.css({ 'visibility' : 'visible' });
		}, 
		function(){
			var bubble = jQuery(this).find(".bubble");
			bubble.css({ 'visibility' : 'hidden' });
			//jQuery(this).find("h5").remove(); 
		}
	);
	
	// tablesorter //
		jQuery("#configurations").tablesorter(); 
		jQuery("#myConfigurations").tablesorter({ 
        // pass the headers argument and assing a object 
        headers: { 
            // assign the secound column (we start counting zero) 
            4: { 
                // disable it by setting the property sorter to false 
                sorter: false 
            }
        } 
    });
	
	// show details //
	jQuery(".collapse").click(function(){
		jQuery(this).toggleClass("closeMe");
		var details = jQuery(this).parents("tr").next();
		if(jQuery(this).hasClass("closeMe")){
			jQuery(this).next().replaceWith("<span>Show</span>")
			jQuery(details).show();
		} else {
			jQuery(this).next().replaceWith("<span>Hide</span>")
			jQuery(details).hide();
		}
		return false;
	});
	// show details version2 //
	jQuery(".collapse2").click(function(){
		jQuery(this).toggleClass("closeMe");
		var details = jQuery(this).parent().next(); // difference
		if(jQuery(this).hasClass("closeMe")){
			jQuery(this).next().replaceWith("<span>Show</span>")
			jQuery(details).show();
		} else {
			jQuery(this).next().replaceWith("<span>Hide</span>")
			jQuery(details).hide();
		}
		return false;
	});
	
	// OS selector //
	jQuery(".osLinux span").addClass("active");
	jQuery(".osSelector .osSelect span").click(function(){
		if(jQuery(this).hasClass("active")){
			
		} else {
			jQuery(".osSelector .osSelect span").removeClass("active");
			jQuery(this).addClass("active");
		}
	});
	
	// equal table heights //
	var getWrapHeight = jQuery(".equalHeights").height();
	
	jQuery(".equalHeights .changeHeights").height(getWrapHeight);

	//jQuery("")
	
	
	/*	
	jQuery(".tablesorter")
		.collapsible("td.collapsible", {
			collapse: true
		})
		.tablesorter({
		// set default sort column
		sortList: [[0,0]]
		// don't sort by first column
		, headers: {7: {sorter: false}}
		// set the widgets being used - zebra stripping
		//, widgets: ['zebra']
		//, onRenderHeader: function (){
			//this.wrapInner("<span></span>");
		//}
		, debug: false
	})
	*/
	//.tablesorterPager({container: jQuery("#pager"), positionFixed: false});
		
	
});

