var OVRIMG = [];
OVRIMG['top_left_menu_arr'] = [];
OVRIMG['top_left_menu_arr'][0] = new Image();
OVRIMG['top_left_menu_arr'][0].src = URL+"tai_nguyen/img/top_left_menu_arr.png";
OVRIMG['top_left_menu_arr'][1] = new Image();
OVRIMG['top_left_menu_arr'][1].src = URL+"tai_nguyen/img/top_left_menu_arr2.png";


jQuery.fn.swap = function(b){ 
    b = jQuery(b)[0]; 
    var a = this[0]; 
    var t = a.parentNode.insertBefore(document.createTextNode(''), a); 
    b.parentNode.insertBefore(a, b); 
    t.parentNode.insertBefore(b, t); 
    t.parentNode.removeChild(t); 
    return this; 
};

function fixed_ads(){
	$('#fixed_ads').css('top', $(window).height() - 230);
	$('#fixed_ads').css('left', $(window).width() - 230);
}

function _loading(){
	$('#loading').draggable().draggable('destroy');
	$('#loading').css('top', ($(window).height() - $('#loading').height())/2);
	$('#loading').css('left', ($(window).width() - $('#loading').width())/2);
}



    $(window).resize(function () {
        _shadow();
		
		//fixed_ads();
    });
    
    function _shadow(){
 
        if ($("#featured_tours H1").length > 0 && !$("#featured_tours H1").hasClass("tour_title")) {
            $('#featured_tours_H1_shadow').css('position', 'absolute').css('top', $("#featured_tours H1").offset().top - 10).css('left', $("#featured_tours H1").offset().left - 10).css('z-index', 1);
        }   
	
	
        $('._shadow').remove();
    $(".shadow").each(function () {
        var _shadow = $("<h2 class='_shadow'>" + $(this).html() + "</h2>");
        _shadow.css('position', 'absolute').css('top', $(this).offset().top - 10).css('left', $(this).offset().left - 10).css('z-index', 1);

        $('body').append(_shadow);
    });   
    }

$(document).ready(function () {

$("A").click(function(){
	if(
		$(this).attr('href') != "" 
		&& $(this).attr('href')[0] != "#" 
		&& $(this).attr('target') != "_blank"
		&& $(this).attr('href').indexOf("tai_nguyen/") == -1
		&& $(this).attr('href').indexOf(".jpg") == -1
	) $('#loading').show('clip');
});

$(".contents").each(function(){
	var rel = Math.floor(Math.random()*1000);
	$(this).find('IMG').each(function(){
		$(this).wrap("<a class='contents_img' rel='rel_"+rel+"' href='"+$(this).attr('src')+"' target='_blank'/>");
	});
});


$(".contents_img").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	500, 
		'speedOut'		:	500, 
		'overlayShow'	:	true,
		'cyclic'	:	true
	});
$("#testimonials A").each(function(){
	if(!$(this).hasClass("tourHref")){
	$(this).fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	500, 
		'speedOut'		:	500, 
		'overlayShow'	:	true,
		'cyclic'	:	true
	});
	}
	});

	//fixed_ads();
    $("#top_menu UL LI A").css("backgroundPosition", "0 -60px").mouseover(function () {
        if ($(this).hasClass("slt")) return;
        $(this).stop().animate({
            backgroundPosition: '0 0px'
        },{ 
			duration	:	200, 
			step		:	function () {
				$(this).css("color", "#fff");
			}
		});
    }).mouseout(function () {
        if ($(this).hasClass("slt")) return;
        $(this).stop().animate({
            backgroundPosition: '0 -60px'
        },{ 
			duration	:	200, 
			step		:	function () {
				$(this).css("color", "#b0b0b0");
			}
		});
    });


/*
	$(".otooltip").tooltip({
		effect: 'slide',
		//position: 'center right'
	});
*/

    //featured_tours_H1_shadow
    if ($("#featured_tours H1").length > 0 && !$("#featured_tours H1").hasClass("tour_title")) {
        var featured_tours_H1_shadow = $("<h2 id='featured_tours_H1_shadow'>" + $("#featured_tours H1").html() + "</h2>");
        featured_tours_H1_shadow.css('position', 'absolute').css('top', $("#featured_tours H1").offset().top - 10).css('left', $("#featured_tours H1").offset().left - 10).css('z-index', 1);

        $('body').append(featured_tours_H1_shadow);
    }

	
	setTimeout('_shadow()',100);
	
	$(".featured_tours_menu").each(function(){
		var items = $(this).find('DIV.featured_tours_menu_item');
		var mheight = 0;
		for(i = 0; i < items.length; i++){
			if($(items.get(i)).height() > mheight){
				mheight = $(items.get(i)).height();
			}
		}
		items.css('height', mheight);
	});

	//$(".featured_tours_menu DIV").mouseover(function(){
	//	$(this).slideUp();
	//	$(this).slideDown();
	//});

	$("#featured_tours DIV.featured_tours_menu DIV.featured_tours_menu_item DIV.featured_tours_menu_item_price").each(function(){
		
		$(this).draggable().css('top', -10).draggable('destroy');
	});
	
	$('#loading').draggable().draggable('destroy');


    $("#top_left_menu DIV:not(.slt)").mouseover(function () {
        if ($(this).hasClass("slt")) return;
        $(this).stop().animate({
            backgroundPosition: '0px 0px'
        }, 150, 'swing', function () {
            $(this).find('.top_left_menu_arr').attr('src', OVRIMG['top_left_menu_arr'][1].src);
        });
    }).mouseout(function () {
        if ($(this).hasClass("slt")) return;
        $(this).stop().animate({
            backgroundPosition: '-365px 0px'
        }, 100, 'swing', function () {
            $(this).find('.top_left_menu_arr').attr('src', OVRIMG['top_left_menu_arr'][0].src);
        });
    });



    $(".category UL LI:last-child").css('border-bottom', '0px');



    $(".category .short_category").hover(
		function () {
			$(this).find('ul').stop().slideDown(100);
		}, 
		function () {
			$(this).find('ul').slideUp(100);
		}
	);
    
    setTimeout('_shadow()',100);
	
	//alert("js.js")
	if($("#top_menu A.slt").length == 0){
		$("#danh_muc__120").addClass("slt");
	}
	$(".featured_tours_menu DIV").click(function(){
		$('#loading').show('clip');
		window.location = ($(this).find('a').attr('href'))
	});
	
	$("#top_left_menu DIV").click(function(){
		$('#loading').show('clip');
		window.location = ($(this).find('a').attr('href'))
	});
	
	$("#logo").click(function(){
		$('#loading').show('clip');
		window.location = URL;
	});
	
	$('#loading').hide('clip');
});
