ddopen = 0;

function mycarousel_initCallback(carousel) {
    jQuery('div.slidectrl').bind('click', function() {
    	var slidx = jQuery(this).attr('slide') * 1;
    	//alert(slidx);
        carousel.scroll(slidx);
        carousel.stopAuto();
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    
    jQuery('li.slide').hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
    jQuery('.slidectrl').removeClass('activeSlide');
    jQuery('#ctrl_' + idx).addClass('activeSlide');
};

function gotoSlide(num) {
	carousel.scroll(num);
}


jQuery('#mycarousel').jcarousel({
	initCallback: mycarousel_initCallback,
	// easing: 'easeInBounce',
	animation: 500,
	auto: 15,
	wrap: 'last',
	scroll: 1,
	itemFirstInCallback:  mycarousel_itemFirstInCallback
	
});

function showdd(ll) {
		jQuery('li#'+ll).find('div.dddd').show();
		jQuery('li#'+ll).addClass("on-top");
		jQuery('li#'+ll).find('div.dddd').addClass("on-top");
		jQuery('li#'+ll).addClass('menuon');
};

function hidedd(ll) {
		jQuery('li#'+ll).find('div.dddd').hide();
		jQuery('li#'+ll).removeClass("on-top");
		jQuery('li#'+ll).find('div.dddd').removeClass("on-top");
		jQuery('li#'+ll).removeClass('menuon');
	};


jQuery(document).ready(function() {

		
	jQuery('#mycarousel').jcarousel({
		initCallback: mycarousel_initCallback,
		// easing: 'easeInBounce',
		animation: 500,
		auto: 15,
		wrap: 'last',
		scroll: 1,
		itemFirstInCallback:  mycarousel_itemFirstInCallback
		
	});
	
	jQuery('td.sked_open').toggle(function() {
		jQuery('tr.second_row').hide();
		var button = jQuery(this).attr('id');
		jQuery(this).addClass('close');
		var id = button.split('_');
		jQuery('tr#second_'+id[1]).show();
	}, function() {
		jQuery('tr.second_row').hide();
		jQuery(this).removeClass('close');
	});
	
	jQuery('a#openall').toggle(function() {
		jQuery('tr.second_row').show();
		jQuery('span#showhideall').html("Hide");
		jQuery('td.sked_open').removeClass('close');
	}, function() {
		jQuery('tr.second_row').hide();
		jQuery('span#showhideall').html("Show");
	});
	
	jQuery('a#hide_details').toggle(function() {
		jQuery('td.details').show();
		jQuery("a#hide_details").html("Hide details &raquo;");
	}, function() {
		jQuery('td.details').hide();
		jQuery("a#hide_details").html("&laquo; Show details");
	});
	
	jQuery('a.ptab').click(function() {
		var showDiv = this.hash.slice(1);
		jQuery('section.player_stats_year').fadeOut("fast");
		jQuery('section#stats_'+showDiv).fadeIn("slow");
		jQuery('a.ptab').removeClass("on");
		jQuery('a#tab_'+showDiv).addClass("on");
	});
	
	jQuery('a.ttab').click(function() {
		var showDiv = this.hash.slice(1);
		jQuery('section.team_stats').fadeOut("fast");
		jQuery('section#stats_'+showDiv).fadeIn("slow");
		jQuery('a.ttab').removeClass("on");
		jQuery('a#tab_'+showDiv).addClass("on");
	});
	
	jQuery('a.ctab').click(function() {
		var showDiv = this.hash.slice(1);
		jQuery('section.coach_stats').fadeOut("fast");
		jQuery('section#coach_'+showDiv).fadeIn("slow");
		jQuery('a.ctab').removeClass("on");
		jQuery('a#tab_'+showDiv).addClass("on");
	});
	
	jQuery("table.sortable").tablesorter({ 
		widgets: ['zebra'],
		textExtraction: function(node) {
		return node.getAttribute('sortvalue') || node.innerHTML;
	 	}
    });
    
    jQuery("div.comparison").toggle(function() {
    	jQuery("div.comptable").hide();
		jQuery(this).find("div.comptable").fadeIn("fast");
	}, function() {
		jQuery("div.comptable").hide();
    });
    
    jQuery("div.comparison").toggle(function() {
    	jQuery("div.comptable").hide();
		jQuery(this).find("div.comptable").fadeIn("fast");
	}, function() {
		jQuery("div.comptable").hide();
    });
    
    jQuery("div.cp").toggle(function() {
		jQuery("div.ct").hide();
		jQuery(this).find("div.ct").fadeIn("fast");
	}, function() {
		jQuery("div.ct").hide();
	});
    
    jQuery("#youtubel").click(function() {
		jQuery('#videoBar-bar').animate({
			'marginLeft' : "0"
		},1000,"swing");
		jQuery(".floatingPlayerBox_gsvb").css('marginLeft','0');
		jQuery(".floatingPlayer_gsvb").css('marginLeft','0');
	});
	
	jQuery("#youtuber").click(function() {
		jQuery('#videoBar-bar').animate({
			'marginLeft' : "-420px"
		},1000,"swing");
		jQuery(".floatingPlayerBox_gsvb").css('marginLeft','210px');
		jQuery(".floatingPlayer_gsvb").css('marginLeft','210px');
	});
	
	jQuery("#mensteamlinks").mouseleave(function() {
		hideteams("mensteamlinks");
	});
	
	jQuery("#womensteamlinks").mouseleave(function() {
		hideteams("womensteamlinks");
	});
	
});


function chgWindow(param) {
	url = param.options[param.selectedIndex].value;
//	alert(url);
	var indImg = '<div class="chgpage"><img src="/pagechange.gif" width="128" height="15" /></div>';
	jQuery("div.selectother").html(indImg);
	window.location=url
}

function switchPlayer(showDiv) {
	jQuery('section.player_stats_year').fadeOut("fast");
	jQuery('section#stats_'+showDiv).fadeIn("slow");
	jQuery('a.ptab').removeClass("on");
	jQuery('a#tab_'+showDiv).addClass("on");
}

function switchTeam(showDiv) {
	jQuery('section.team_stats').fadeOut("fast");
	jQuery('section#stats_'+showDiv).fadeIn("slow");
	jQuery('a.ttab').removeClass("on");
	jQuery('a#tab_'+showDiv).addClass("on");
}

function switchCoaches(showDiv) {
	jQuery('section.coach_stats').fadeOut("fast");
	jQuery('section#coach_'+showDiv).fadeIn("slow");
	jQuery('a.ctab').removeClass("on");
	jQuery('a#tab_'+showDiv).addClass("on");
}

function showNext(showDiv) {
	jQuery('div.arch_select').hide();
	jQuery('div#arch_'+showDiv).fadeIn("fast");
}

function showSubmit(showDiv) {
	jQuery('div#arch_button').fadeIn("slow");
	if (showDiv != 'team_md1') {
		unset('team_md1');
	}
	if (showDiv != 'team_md3') {
		unset('team_md3');
	}
	if (showDiv != 'team_wd1') {
		unset('team_wd1');
	}
	if (showDiv != 'team_wd3') {
		unset('team_wd3');
	}
	if (showDiv != 'history_md1') {
		unset('history_md1');
	}
	if (showDiv != 'history_md3') {
		unset('history_md3');
	}
	if (showDiv != 'history_wd1') {
		unset('history_wd1');
	}
	if (showDiv != 'history_wd3') {
		unset('history_wd3');
	}
}

function unset(showDiv) {
	jQuery('#'+showDiv).find('option:first').attr('selected', 'selected').parent('select');
	//var field = jQuery('select#'+showDiv);
 	//field.val(jQuery('option:first', field).val());
}

function indicator() {
	var indImg = '<div class="chgpage"><img src="http://himg.uscho.com/pagechange.gif" width="128" height="15" /></div>';
	jQuery("div.selectother").html(indImg);
}

function teamdd() {
	jQuery('li#li_teams').addClass('ddon');
	jQuery('#teamsdd').slideDown(800);
	if (ddopen!=1) {
			jQuery.get('/dd.php', function(data){
			jQuery('#teamsdd').html(data);
			ddopen = 1;
		});
	}
}

function teamddclose() {
	jQuery('li#li_teams').removeClass('ddon');
	jQuery('#teamsdd').slideUp(300);
}

function chgHtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	return newEl;
};
