function writeTo(u, d) {
	var l="\x6D\x61\x69";
	l+="\x6C\x74\x6F\x3A"+u;
	window.location=l+"\x40"+d;
	}

$(document).ready(function(){

	// FAQ
	$(".a").hide();
	$(".q").click(function()
	{
		$(this).toggleClass("q").toggleClass("q_active");
		$(this).next(".a").slideToggle(100);
		});
	
	// lightBox
	$(function() {
		$('a[rel=slides]').lightBox();
		});
	
	// Slider
	$('.dots li:first-child a').addClass('activeSlide');
	function slide(i) {
		$('.dots li:nth-child(' + (i + 1) + ')').click(function() {
			$(this).parent().find('a.activeSlide').removeClass('activeSlide');
			$(this).children('a').addClass('activeSlide');
			var p = $(this).parent().parent().width();
			$(this).parent().parent().find('.slider').animate({left: (i * - p) + "px"},400);
		});	
	}
	for (var i = 0; i < 10; i++) { slide(i); }
	
	// Cycle
	$('#banner.home .slides')
	.cycle({
		fx: 'fade',
		speed: 500, 
    	timeout: 10000,
		pause: 1,
		pager: '#banner.home .dots',
		pagerEvent: 'mouseover'
	});
	
	// Cycle
	$('#book .slides')
	.cycle({
		fx: 'fade',
		speed:		200, 
    	timeout:	0,
		next:		'#next', 
    	prev:		'#prev',
	});
	
	var x = $('.dots').width();
	var p = $('.dots').parent().width()/2;
	var x = p-(x/2);
	//$('.dots').css({left: x + "px"});
	$('.dots').css({left: x - 5 + "px"});
	
	
	// Download
	$('.goodies a').hover(function() {
		$(this).children('.download').fadeIn(200);
	}, function () {
		$(this).children('.download').fadeOut(200);
	});
	
	// Video
	// getPageSize() by quirksmode.com
	function ___getPageSize() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	};
	
	/* getPageScroll() by quirksmode.com */
	function ___getPageScroll() {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	};
		
	$('.playvideo').click(function() {
		$('embed, object, select').css({'visibility':'hidden'});
		var myvideo = $(this).attr('href');
		$('body').append('<div id="video-overlay"></div><div id="myvideo"><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/' + myvideo + '&hl=en_US&fs=1&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + myvideo + '&hl=en_US&fs=1&rel=0&hd=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></div>');
		$('#myvideo').hide();
		var arrPageSizes = ___getPageSize();
		$('#video-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();
		var arrPageScroll = ___getPageScroll();
		$('#myvideo').css({top:arrPageScroll[1] + (arrPageSizes[3]/10)}).fadeIn(500);
		$('#video-overlay').click(function() {
			$(this).next('#myvideo').remove();
			$(this).fadeOut(function() { $(this).remove(); });
			$('embed, object, select').css({'visibility':'visible'});
		});
		return false;
	});
	
	$(window).resize(function() {
		var arrPageSizes = ___getPageSize();
		$('#video-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});
		var arrPageScroll = ___getPageScroll();
		$('#myvideo').css({top:arrPageScroll[1] + (arrPageSizes[3] / 10),left:arrPageScroll[0]});
	});
//$('#tester').html('xxx');
});
