$(document).ready(function() {
   	if($('flashcontent')){
    	swfobject.registerObject("architecture", "9.0.0"); 
    }
    externalLinks();
	try{Typekit.load();}catch(e){}
	
	if(jQuery('#game').children().size()>1){
		$('#game').addClass('jcarousel-skin-key');
		var num = ($('#game').children().size());
		$('#game').jcarousel({
		scroll: 1,
        initCallback: gamecarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
		});
		$('#gcontrols').find(':nth-child(1)').addClass('active');
	}
});

function gamecarousel_initCallback(carousel) {
  $('.game-control').each(function(i){
  	$(this).find('a').bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(i+1));
		changeThumbs($(this).parent());
		$(this).attr("href", "#");
		return false;
    });
   //jQuery('.jcarousel-scroll select').bind('change', function() {
    //    carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
    //    return false;
    //});
	 });
};

function changeThumbs(thumb){
	$('.game-control').each(function(i){
			$(this).removeClass('active');							   
	});
	thumb.addClass('active');
}


function externalLinks() {  
 if (!document.getElementsByTagName) return;  
 var anchors = document.getElementsByTagName("a");  
 for (var i=0; i<anchors.length; i++) {  
   var anchor = anchors[i];  
   if (anchor.getAttribute("href") &&  
       anchor.getAttribute("rel") == "external")  
     anchor.target = "_blank";  
 }  
}