$(document).ready(function() {
	
	$('#header').click(function() {
		document.location.href = baseUrl;
	});
	
	var bg = '';
	$('#buttons ul li').mouseover(function() {
		if ($(this).attr('class') == 'active') return false;
		var id = this.id;
		if (this.id.substring(0, 5) != 'menu_') return false;
		bg = $(this).css('background-image');
		$(this).css({ 'background-image' : bg.replace('.gif', '_ro.gif')});
	}).mouseout(function() {
		if ($(this).attr('class') == 'active') return false;
		if (bg == '') return false;
		$(this).css({ 'background-image' : bg });
	}).click(function() {
		if ($(this).attr('class') == 'active') return false;
		var url = $(this).find('a:first-child').attr('href');
		document.location.href = baseUrl + url;
	});
	
	var iphone_bg = baseUrl + '/media/iphone/iphone_ico_screen1.gif';
	$('#iphone-gallery img').mouseover(function() {
		if ($(this).hasClass('active')) return false;
		iphone_bg = $(this).attr('src');
		$(this).attr('src', iphone_bg.replace('.gif', '_ro.gif'));
		$('#iphone-inner').css({'background-image' : iphone_bg.replace('_ico', '')});
	}).mouseout(function() {
		if ($(this).hasClass('active')) return false;
		if (iphone_bg == '') return false;
		$(this).attr('src', iphone_bg);
	}).click(function() {
		$('#iphone-gallery').children().each(function() {
			$(this).removeClass("active");
			$(this).attr('src',  $(this).attr('src').replace('_ro.gif', '.gif'));
		});
		
		var screen = this.id.replace('ico_', '');
		var moveToX = 0 - parseInt(screen.replace('screen', '')-1) * 168;
		$('#iphone-inner').animate({'left' : moveToX+'px'}, 500);
		$(this).attr('src',  $(this).attr('src').replace('.gif', '_ro.gif'));
		$(this).addClass('active');
	});
	
});

window.onload = function() {
	var links = document.getElementsByTagName('a');
	for (var i=0;i < links.length;i++) {
	  if (links[i].className == 'new-window') {
	      links[i].onclick = function() {
	          window.open(this.href);
	          return false;
	      };
	  }
	}
};
