// JavaScript Document

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function getAutoplayCookieValue() {
	var value = getCookie("EYEPET_AUTOPLAY");
	return value;
}


function changelang()
{
	document.language.submit();	
}

function submitlanguage() {
	document.language.submit();
}

$(document).ready(function(){

	currentcolor = $('#theme_outline').attr('class');
	$('#background_select ul li.' +currentcolor+ ' a').addClass('active');
	$('#lang').sSelect();
	
	//set max height of dropdown
	var selectbox = $('#thelanguage').sSelect({ddMaxHeight: '105px'});

	//change language
	selectbox.change(function(){changelang();});

	// change background
	$('#background_select a').click(function() {
		$('#background_select a').removeClass('active');
		$(this).addClass('active');
		var selectedColor = $(this).attr('title');

		$.post(dotdotpath + "settheme.cfm", {colour: selectedColor}, function(data){
			var currentcolor = $('#theme_outline').attr('class');
			$('#theme_outline').removeClass().addClass(selectedColor);
		});		
		

		return false; 
	});

	// Tabs
	$('.tab_nav a').click(function() {
		
		var clickedTabId = $(this).attr('id').match(/\d+/);
		var tabContentToDisplay = "tab_content_" + clickedTabId;
		
		$('.downloads .tabs_content ul').hide();
		$('.downloads #' + tabContentToDisplay).show();
		$('.downloads .tab_nav li').removeClass("selected");
		$(this).parent().addClass("selected");
		
		// make sure dropdown elements are in initial state
		$('.dropdown').removeClass('expanded');
		
		
		return false;
		
	});
	
	//nav
	$('ul#main_nav li#meet_eyepet').hover(function() {
		handleClickeyepet();
	});
		$('ul#main_nav li#meet_eyepet').mouseleave(function() {
		handleClickeyepet();
	});
	$('ul#main_nav li#fun_and_games').hover(function() {
		handleClickrocket();
	});	$('ul#main_nav li#fun_and_games').mouseleave(function() {
		handleClickrocket();
	});
	$('ul.product_nav li#prod_nav_item_epf a').hover(function() {
		handleClickeyepetfriend();
	});	$('ul.product_nav li#prod_nav_item_epf a').mouseleave(function() {
		handleClickeyepetfriend();
	});	
	$('ul.product_nav li#prod_nav_item_epa a').hover(function() {
		handleClickeyepetmove();
	});	$('ul.product_nav li#prod_nav_item_epa a').mouseleave(function() {
		handleClickeyepetmove();
	});	
	$('ul.product_nav li#prod_nav_item_eme a').hover(function() {
		handleClickeyepetpsp();
	});	$('ul.product_nav li#prod_nav_item_eme a').mouseleave(function() {
		handleClickeyepetpsp();
	});		
	$('ul.product_nav li#prod_nav_item_epsp a').hover(function() {
		handleClickeyepetadv();
	});	$('ul.product_nav li#prod_nav_item_epsp a').mouseleave(function() {
		handleClickeyepetadv();
	});		
	
	$('ul#main_nav li#buy_eyepet a.pill_btn_blue').hover(function() {
		handleClickpackshot();
	});	$('ul#main_nav li#buy_eyepet a.pill_btn_blue').mouseleave(function() {
		handleClickpackshot();
	});				
	
		
    var flashmonkey;
	var flashrocket;
	var eyepetfriend;
	var eyepetmove;
	var eyepetpsp;
	var eyepetadv;
	var packshot;
	
      function flashnav() {
         if (document.getElementById) {
            flashmonkey = document.getElementById("nav_monkey");
			flashrocket = document.getElementById("nav_rocket");
			eyepetfriend = document.getElementById("prod_friends");
			eyepetmove = document.getElementById("prod_move");
			eyepetpsp = document.getElementById("prod_psp");
			eyepetadv = document.getElementById("prod_adv");
			packshot = document.getElementById("nav_packshot");
         }
      }

	function handleClickeyepet(){
		 if (flashmonkey) {
            flashmonkey.controlAnimation();
         }
	}
	
	function handleClickrocket(){
		 if (flashrocket) {
            flashrocket.controlAnimation();
         }
	}	
	
	function handleClickeyepetfriend(){
		 if (eyepetfriend) {
            eyepetfriend.controlAnimation();
         }
	}	
	
	function handleClickeyepetmove(){
		 if (eyepetmove) {
            eyepetmove.controlAnimation();
         }
	}
	
	function handleClickeyepetpsp(){
		 if (eyepetpsp) {
            eyepetpsp.controlAnimation();
         }
	}
	
	function handleClickeyepetadv(){
		 if (eyepetadv) {
            eyepetadv.controlAnimation();
         }
	}	
	
	function handleClickpackshot(){
		 if (packshot) {
            packshot.controlAnimation();
         }
	}						

	flashnav();
	// show eyepet sub nav
	$('#buy_eyepet .pill_btn').click(function() {
		$(this).fadeOut('100', function() {
			$('#buy_eyepet_subnav').slideDown('500');
			$('#main_nav #buy_eyepet .inner').css('padding-bottom','5px');			
		});
		return false;		
	})
	
	// hide eyepet sub nav
	$('#buy_eyepet_subnav .close').click(function() {
		$('#buy_eyepet_subnav').slideUp('200', function() {
			$('#buy_eyepet .pill_btn').fadeIn('100');	
			$('#main_nav #buy_eyepet .inner').css('padding-bottom','15px');				
		});
		return false;		
	})	
	
	// downloads dropdown
	$('.dropdown .expand').click(function() {

		var dropdown = $(this).parents('.dropdown');
		
		if($(dropdown).hasClass('expanded')) {
			$(dropdown).removeClass('expanded');			
			$(dropdown).find('ul').slideUp();				
		} else {
			$(dropdown).addClass('expanded');
			$(dropdown).find('ul').slideDown();						
		}
	
		return false;
		
	})
		
	// games slideshow
	$('#games_slideshow .slides').cycle({
		fx:      'scrollHorz',
		prev:   '#games_slideshow .prev',
		next:   '#games_slideshow .next',
		timeout:  0,
		easing:  'easeInOutBack',
		speed: '1000'		
    });
	
	// noflash slideshow
	$('#home_noflash .slides').cycle({
		fx:      'scrollHorz',
		prev:   '#home_noflash .prev',
		next:   '#home_noflash .next',
		timeout:  3000,
		easing:  'easeInOutBack',
		speed: '1000'		
    });	
	
	// disable coming soon buttons
	$('ul.games_and_activities .pill_btn_grey').click(function() {
		
		return false;
		
	});
	
	// preload background images
     $(document).smartpreload({ images: [dotdotpath + 'images/layout/bg_theme_outline_green.jpg',dotdotpath + 'images/layout/bg_theme_outline_blue.jpg',dotdotpath + 'images/layout/bg_theme_outline_pink.jpg',dotdotpath + 'images/layout/bg_theme_outline_yellow.jpg',dotdotpath + 'images/layout/bg_flash_header_green.jpg',dotdotpath + 'images/layout/bg_flash_header_blue.jpg',dotdotpath + 'images/layout/bg_flash_header_pink.jpg',dotdotpath + 'images/layout/bg_flash_header_yellow.jpg']});
	
	// add class to correct baselines in OSX
	if(navigator.platform.match('Mac') !== null) {
		$('body').addClass("osx");
	}

	
});	




