/*	Author : Stuart Grant */
$(document).ready(function(){
	/*search clear*/
	$("#form_box .txt, #form_box textarea").not('input[type=submit], .noclear').focus(function() {
		$(this).addClass("focus")
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		$(this).removeClass("focus")
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	})
	
	$('.j_hide').css('display','none');

	$('#signUp').colorbox({width:"395", height:"580px", iframe:true,opacity :0.5}, function(){  
							$('#cboxTitle').hide();	
	})
	$('a[rel="imageGallery"]').colorbox({opacity :0.5, transition:"fade"});
	$('a[rel="videoGallery"]').colorbox({iframe:true, innerWidth:720, innerHeight:405,opacity :0.5});
	
		
	$("a").not('#lang_select a, #bookshelf ul a, .carousel a').click(function () { 
		var targetScroll = this.hash;
		$(this).parents('body').scrollTo( targetScroll, 1000, { queue:true }, {easing:'elasin'} );
		return false; 
	});
	
	$('.events thead a').live('click', function() 
	{
			var getURL = $(this).attr('href');
			var getContent = getURL+ ' #cal_load .calander';
			$(".events #cal_load").load(getContent);
			return false; 
	});

 	$(".calander tbody tr td a").hover(
      function () {
        $(this).find('.pop').show().css({ 'opacity' : 0}).animate({opacity: 1}, 250);
		}, 
      function () {
        $(this).find('.pop').hide();
      }
    );
	
	if ( $('.archive').length > 0 ) {
			$(".archive ul li").not('.archive ul li li').addClass('closed');
			$(".archive ul li.closed ul").hide();
			$(".archive ul li a").not('.archive ul li li a').click(function () { 
					 $(this).stop().parent('li').toggleClass('closed').toggleClass('open');						  
					 $(this).stop().siblings('ul').slideToggle(600);
					return false; 
			});
		}
		
	if ( $('.country').length > 0 || $('.language').length > 0 ) {
		$("h5.country, .language").hide();
	}

	$("#lang_select li a").click(function () {
			 $(this).addClass('active');
			 $(this).parents('#booking_links').find('.language').hide();
			 $(this).parents('#booking_links').find(this.hash).slideToggle();
			return false; 
	});
	
	$('#img_list').children().hover(function() {
	 $(this).siblings().stop().fadeTo(500,0.5);
		 }, function() {
	 $(this).siblings().stop().fadeTo(500,1);
	 }); 
	
});

$(document).ready(function(){
    $('#bookshelf ul li a').click(function () {
			$(this).parents('#bookshelf').find('.active').removeClass('active');						
			$(this).addClass('active');
			$('#bookshelf ul li a.active img').animate({opacity : 0.5},200).animate({opacity : 1},200);	
            $(".selected #load").remove();
			$.ajax({
				type: "GET",
				url:  $(this).attr('rel'),
				dataType: "xml",
				success: parseXml
			  });
			$(".selected").append('<div id="load"></div>');
            return false; 
    });
	
	function parseXml(xml)
		{
		  $(xml).find("page").each(function()
		  {
			 var imgSrc = $(this).find('image').text();
			 var newImg = new Image();
			 var drawimg = $(newImg).attr("src", imgSrc );
			 var getURL = $('#bookshelf ul li a.active').attr('href');
			
			$(".selected #load").append($(this).find('title').text());
			$(".selected #load").append($(drawimg).attr('class','block_link'));
			$(".selected #load").append($(this).find('description').text());
			$(".selected #load").append('<a href="'+getURL+'" class="cta"><span>Continue Reading</span></a>'); /*ie7 :( */
			
		  });
		}
		
	 $('#bookshelf ul li a:first').click();
});

$(function () {
	if ( $('#books .selected').length > 0 ) {
	  var msie6 = $.browser == 'msie' && $.browser.version < 7;
	  if (!msie6) {
		var top = $('.selected').offset().top - parseFloat($('.selected').css('margin-top').replace(/auto/, 0));
		$(window).scroll(function (event) {
		  var y = $(this).scrollTop();
		  if (y >= top) {
			$('.selected').addClass('fixed');
		  } else {
			$('.selected').removeClass('fixed');
		  }
		});
	  } 
	}
});
