// JavaScript Document
/**
 * @author Alexander Farkas
 * v. 1.02

(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
 */


$(function(){
		   $('a[rel=external]').attr('target','_blank'); 

	// RIGHT COLUMN SPONSOR IMAGE FADE	   
	$('#fade-logos').cycle('fade');
	
	/* NAVIGATION BACKGROUND HOVER COLOR
	$('#navMenu a').mouseover(function(){
		$(this).stop().animate({backgroundPosition:"(0 -250px)"}, {duration:300})
		//$('#navMenu li#selected a').stop();
	
	}).mouseout(function(){
		$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:200})
		$('#navMenu li#selected a').stop();	
	});
	*/

// START AJAX CALL FOR THE HOTEL & TRAVEL PAGE
    $.ajax({
        type: "GET",
        url: "PreBuilt/xml/rising/hotel-pics.xml",
        dataType: "xml",
        success: xmlParser
	});
	function xmlParser(xml) {
    //$('#load').fadeOut();
	
    $(xml).find('pic').each(function () {	
			var id = $(this).attr("id");	
			var url = $(this).find("url").text();
			var img = $(this).find("img").text();
			var title = $(this).find("title").text();
	        $('#hotel-thumbs').append('<div class="thumbnail-img" id="thumbnail-img'+ id+ '"><a href="' + url + '" class="link'+ id + '" rel="group"><img src="' + img + '" alt="' + title  + '" /></a></div>');			
 			
			$('.thumbnail-img:nth-child(5n)').css({'margin-right':0});
			
			(function() {
			   // Hide the elements initially
			   var lis = $('.thumbnail-img').hide();
			
			   setTimeout( function() {
				  var i = 0;
				  (function displayImages() {
					 lis.eq(i++).fadeIn(200, displayImages);
				  })();
			   }, 300);
			})();
		// END FADE IN 
	
	
		// FANCY BOX THE HOTEL & TRAVEL IMAGES
		$("a[rel=group]").fancybox({
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'titlePosition' 	: 'over',
			'cyclic'			: 'true',
			'overlayColor'		: '#082151',
			'overlayOpacity'    : '0.2',
			'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    	return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
			}
		});

    });
	
	
	}
	
	// SPONSOR FLIP 
	$('.sponsor:nth-child(3n)').css({'margin-right':0});
	$('.sponsorFlip').bind("click",function(){
		
		// $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
		
		var elem = $(this);
		
		// data('flipped') is a flag we set when we flip the element:
		
		if(elem.data('flipped'))
		{
			// If the element has already been flipped, use the revertFlip method
			// defined by the plug-in to revert to the default state automatically:
			
			elem.revertFlip();
			
			// Unsetting the flag:
			elem.data('flipped',false)
		}
		else
		{
			// Using the flip method defined by the plugin:
			
			elem.flip({
				direction:'lr',
				speed: 250,
				onBefore: function(){
					// Insert the contents of the .sponsorData div (hidden from view with display:none)
					// into the clicked .sponsorFlip div before the flipping animation starts:
					
					elem.html(elem.siblings('.sponsorData').html());
				}
			});
			
			// Setting the flag:
			elem.data('flipped',true);
		}
	});
	
	
	
	
	
	
// END ALL JS

});
