$(document).ready(function() {

	/* Menu */
	$('.menu .page-item-37 a').attr({
		href: 'http://www.baanoom.com/',
		target: '_blank'
	});
	
	// General
	$('img').removeAttr('width').removeAttr('height').removeAttr('alt');
	
	// Home Page	
	$('div .blog-column > div[id^="post"]').each(function(i, post){
		var $post= $(post);
		var content_link = $('a[rel="bookmark"]', $post).attr('href');
		$('img', $post).parent().attr('href', content_link);
	})
					
	// Blog Reading Page
	$('.single .entry-content img').parent('a').slimbox();
	$('.category .entry-content img').parent('a').slimbox();
	
	// Book Detail Page
	
	// Click thumbnail to change image in the main area.
	$('#preview-thumbnail .gallery a').click(function() {
		var imgpath = $(this).attr('href');
		$('#preview-img').fadeOut('slow');
		$('#preview-area').queue(function () {
			$('#preview-area').addClass('waiting');
			$('#preview-area').dequeue();
		});
		$('#preview-img').queue(function () {
			$('#preview-img').attr({src: imgpath});
			$('#preview-area a').attr({href: imgpath});
			$('#preview-img').dequeue();
		});
		$('#preview-img').load(function() {
			$('#preview-area').removeClass('waiting');
			$('#preview-img').fadeIn('slow');
		});
		return false;
	});
	
	$('#preview-thumbnail .gallery br').remove();
	$('#preview-thumbnail .gallery').wrapInner('<ul id="thumbnail-carousels"></ul>');
	$('#thumbnail-carousels').jcarousel({
		scroll:		7,
		visible:	7,
		wrap:		'circular',
	});
	
	// Set first image to display.
	var imgpath = $('.jcarousel-item-1 .gallery-icon a').attr('href');
	$('#preview-img').attr({src: imgpath}).wrap('<a></a>');
	$('#preview-area a').attr({href: imgpath});
	$('#preview-area').addClass('waiting');
	$('#preview-img').load(function() {
		$('#preview-area').removeClass('waiting');					  
		$('#preview-img').fadeIn();
	});
	
	$('#preview-area a').slimbox();
	
	//Book Review Section
	$('#review-section').accordion();
	
	//Oom Loves Tabs
	$('.home #oomlove-tabs').tabs({ 
		event: 'mouseover', 
		collapsible: true, 
		selected: -1, 
		fx: { opacity: 'toggle', duration:'fast' } 
	});
	
	$('.page-template-oomloves-php #oomlove-tabs').tabs({ 
		fx: { opacity: 'toggle', duration:'fast' } 
	});
	
	// Get Video Content
	$('#new-video-list').accordion({ collapsible: true });
	$('#old-video-list').accordion({ collapsible: true });
	
	$('#new-video .video-list a').click(function () {
		$('#new-video-content').addClass('loading-content').empty();
		var videoid = $(this).attr('videolink');
		$('#new-video-content').load('/wp/get-video-content/?id='+videoid, function() {
			$('.loading-content').removeClass('loading-content');
		});
		return false;
	});
	
	$('#old-video .video-list a').click(function () {
		$('#old-video-content').addClass('loading-content').empty();
		var videoid = $(this).attr('videolink');
		$('#old-video-content').load('/wp/get-video-content/?id='+videoid, function() {
			$('.loading-content').removeClass('loading-content');
		});
		return false;
	});
	
	// Download Page
	$('#download-list li a').click(function () {
		$('#download-content').addClass('loading-content').empty();
		var downloadid = $(this).attr('downloadlink');
		$('#download-content').load('/wp/get-download-content/?id='+downloadid, function() {
			$('.loading-content').removeClass('loading-content');
		});
		return false;
	});
	
	//$('#download-list').accordion({ collapsible: true, active: false });
	
	// Press Page
	$('#press-list li a').click(function () {
		$('#press-content').addClass('loading-content').empty();
		var pressid = $(this).attr('presslink');
		$('#press-content').load('/wp/get-press-content/?id='+pressid, function() {
			$('.loading-content').removeClass('loading-content');
		});
		$('#press-list .current_post').removeClass('current_post');
		$(this).addClass('current_post');
		
		return false;
	});
	
	$('#press-list').accordion({ collapsible: true });
	$('#press-content a').slimbox();
		
	// Register Form
	$('#register-area').load('/wp/wp-login.php?action=register #registerform');
	
	// Comment Form
	$('#commentform input, #commentform textarea').labelify({
  		text: 'label'
	});

});
