// JavaScript Document

jQuery.noConflict();


jQuery(document).ready(function () {

	jQuery("#tabs_toDo").tabs();
	jQuery("#tabs_plan").tabs();
	jQuery('#fullBorder').corner();
	jQuery('.rounder').corner();
	ytVideos();
	ajaxCall();
	jQuery('#ppy1').popeye();

	//Caption Sliding (Partially Hidden to Visible)
	jQuery('.boxgrid.caption').hover(function(){
		jQuery(".cover", this).stop().animate({top:'70px'},{queue:false,duration:100});
	}, function() {
		jQuery(".cover", this).stop().animate({top:'100px'},{queue:false,duration:100});
	});

    jQuery('#lnkDisclaimer').click(function() { 
        jQuery.blockUI({ 
            message: jQuery('#contentDisclaimer'), 
            css: { top: '20%',padding: '10px' } 
        }); 
    }); 	
	
    jQuery('#lnkCloseModal').click(function() { 
        jQuery.unblockUI();
    }); 	

	slidePicture();			
	var fcSrc = '<img src="http://media.fastclick.net/w/tre?ad_id=25419;evt=18488;cat1=23592;cat2=23593;rand='.concat(Math.floor(Math.random()*99999)).concat('" width="1" height="1" border="0">');
	jQuery("#fastclick").attr("src", fcSrc);
});

//a custom format option callback
var addressFormatting = function(text){
	var newText = text;
	//array of find replaces
	var findreps = [
		{find:/^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>'},
		{find:/([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
		{find:/([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2'},
		{find:/([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
		{find:/(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>'}
	];

	for(var i in findreps){
		newText = newText.replace(findreps[i].find, findreps[i].rep);
	}
	return newText;
}

function ajaxCall() {
	jQuery.ajaxSetup({ cache: false });
	var lang = jQuery.url.param("ididioma");
	var langVar;
	if (lang != "") {
		langVar = "?lang=" + lang;
	}
    jQuery("#tabHotel").load("/ict/paginas/buscador/ajaxProductByFilter.asp?idprod=1&filter=REGION");
    jQuery("#newsContainer").load("/ict/version/asp/homeNews.asp" + langVar);
    jQuery("#featureNote").load("/ict/version/asp/homeFeatureNote.asp" + langVar);
}

//instant
function instantHome() {
	var iPlaya = new Array();
	iPlaya = [
		{source:'http://www.visitcostarica.com/newDesign/images/istack/iPlaya1.jpg', options:'{tilt:"l",text:"Humpback Whale",fontattr: [50,50,120]}' },
		{source:'http://www.visitcostarica.com/newDesign/images/istack/iPlaya2.jpg', options:'{tilt:"r",text:"Tortuguero Nat. Park",fontattr: [50,50,120]}' },
		{source:'http://www.visitcostarica.com/newDesign/images/istack/iPlaya3.jpg', options:'{tilt:"l",text:"Gandoca - Manzanillo",fontattr: [50,50,120]}' }
	];
	function init_ImageStack() {
		cvi_istack.add(document.getElementById('iPlaya'),{
			imagearray: iPlaya,
			mainwidth: 250,
			mainheight: 200,
			playdelay: 4000,
			playscript: 'cvi_instant',
			noiefade: true
		});
	}
	if(window.attachEvent) {
		window.attachEvent("onload", init_ImageStack);
	}else {
		window.addEventListener("load", init_ImageStack, false);
	}
}

function slidePicture() {
	jQuery("#pikame").PikaChoose({speed:10000});
}

function ytVideos() {
	function mycarousel_initCallback(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});

		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};
	jQuery('.ytLink').each(function(index) {
		var imgPath = jQuery.jYoutube(jQuery(this).attr('href'), 'small');
		jQuery(this).find("img").attr("src", imgPath);
	});
	jQuery('#mycarousel').jcarousel({
		auto: 10,
		wrap: 'last',
		initCallback: mycarousel_initCallback
	});
}
