function init() {
	//sidebar fix
	if ( $('#main div.sidebar-bottom').length && $('#main div.sidebar-top').height()<167 ) {
        $('#main div.sidebar-top').height(167);
	}

	//scroll to element
	$('a.anchor-link').click(function(){
		var elem = $(this).attr('href');
	    $('html,body').animate({scrollTop: $(elem).offset().top}, 500);
	    return false;
	});
	
	//template functions(try/catch)
    try { initTemplate(); } catch(err) { }
    
	//pngfix
    try { initPngFix(); } catch(err) { }
}

function switchBackground(href,dest) {
	var bgImage = virgin ? 'css/virgin/loading.gif' : 'css/loading.gif';
    dest.css({ backgroundImage: 'url('+WEB_CONTENT+bgImage+')' });
    
    //if (!isDefined('doNotSlide') || !doNotSlide) $('html,body').animate({scrollTop: dest.offset().top}, 500);
    if (!isDefined('doNotSlide') || !doNotSlide) $('html,body').animate({scrollTop: 0}, 500);

	var img = new Image();
	$(img).load(function () {
	    dest.css({ backgroundImage: 'url('+href+')' });
	}).error(function(){
	    alert('Ocurrió un error al cargar la imagen: '+href);
	}).attr('src',href);

	return false;
}

function isDefined(variable) {
	return (typeof(window[variable]) == "undefined")?  false: true;
}

function initContact() {
	setTimeout(function(){
		$('#TB_title').addClass('enabledMe');
	    $('#TB_window').addClass('bg-contacto');
	}, 100);
}

function showThickboxTitle() {
	setTimeout( function() {
	    $('#TB_closeAjaxWindow').show();
	}, 100);
}

function initDestinosSidebar() {
    $('#sidebar div.sidebar-menu a.item').click(function(){
        if ( $(this).hasClass('current') ) return false;
        if ( $(this).hasClass('realLink') ) return true;
		$('#sidebar div.sidebar-menu a.item').not(this).removeClass('active').parent().find('ul.destinos').slideUp();
        $(this).addClass('active').parent().find('ul.destinos').slideDown();
        return false;
	});
}

