jQuery(function(){
	// Cufon for typography
	Cufon.replace('.stone-medium', { 
		fontFamily: 'stoneMedium'
	});
	Cufon.replace('.stone-semi', {
		fontFamily: 'stoneSemi'
	});
	Cufon.replace('.btn-club .stone-semi', {
		fontFamily: 'stoneSemi'	, 
		textShadow: '#235B35 0 -1px'
	});
	Cufon.replace('.btn-club .stone-medium', {
		fontFamily: 'stoneMedium'	, 
		textShadow: '#235B35 0 -1px'
	});
	Cufon.replace('.btn-metal-big .stone-semi', {
		fontFamily: 'stoneSemi'	, 
		textShadow: '#FFF 0 1px'
	});
	
	// MRW finder
	jQuery('#mrw-finder-forms').cycle({ 
		fx: 'scrollHorz', 
		speed: 'fast', 
		timeout: 0, 
		pager: '#mrw-finder-selector', 
		pagerAnchorBuilder: function(idx, slide) {
			return '#mrw-finder-selector li:eq(' + idx + ') a'; 
		}
	});
	
	// Tooltip forms
	jQuery('.we-call').cluetip({
		activation: 'click', 
		width: 270,
		topOffset: 30,
		titleAttribute: '',
		positionBy: 'bottomTop',
		dropShadow: false,
		cluetipClass: 'rounded',
		arrows: true
	});
	
	jQuery('.we-call-local').cluetip({
		activation: 'click', 
		width: 270,
		topOffset: 30,
		titleAttribute: '',
		positionBy: 'bottomTop',
		dropShadow: false,
		cluetipClass: 'rounded',
		arrows: true,
		local:true
	});
	
	jQuery('#client-access').cluetip({
		activation: 'click', 
		width: 270,
		topOffset: 35,
		titleAttribute: '',
		positionBy: 'bottomTop',
		dropShadow: false,
		cluetipClass: 'rounded',
		arrows: true
	});
	
	// Reasons slideshow
	jQuery('#reasons-slides').cycle({ 
		fx: 'fade', 
		speed: 'fast', 
		timeout: 10000,
		prev: '#reasons-prev',
		next: '#reasons-next',
		before: reasonsBefore
	});
	
	// .last clases to delete borders
	jQuery('.post:last, .side-post:last').addClass('last');
	
	// Language selector
	jQuery('#language-selector').live('click', function(){
		jQuery('#language-list').show('fast').delay(3000).hide('fast');
	});
	
	// Favourite products
	jQuery('.fav').live('click',function(){
		jQuery(this).toggleClass('favd');
	});
	
	// Service images as backgrounds (Source: http://maxvoltar.com/archive/rounded-corners-on-images-css-only)
	var servImg = jQuery('.product-img, .pack-img');
	var imgURI = servImg.attr('src');
	
	servImg.parent().css('backgroundImage','url('+imgURI+')');
	servImg.css('visibility', 'hidden');
	
	// Zebra lists
	jQuery('.zebra tr:odd, .zebra li:odd').addClass('odd');
	jQuery('.zebra tbody tr:first').addClass('first');
	jQuery('.zebra tbody tr:last').addClass('last');
	
	// Datepicker
	jQuery('.datepicker').each(function(){
		var $this = jQuery(this);
		
		jQuery($this).DatePicker({
			format:'d/m/Y',
			date: jQuery($this).val(),
			current: jQuery($this).val(),
			start: 1,
			position: 'right',
			onBeforeShow: function(){
				jQuery($this).DatePickerSetDate(jQuery($this).val(), true);
			},
			onChange: function(formated, dates){
				jQuery($this).val(formated);
				jQuery($this).DatePickerHide();
			}
		});
	});
	
	// Alerts form - Tooltip
	jQuery('#alert-email, #alert-sms').change(function(){
		var theInput = jQuery(this).parent().siblings('input');
		
		if (theInput.attr('disabled')) {
			theInput.removeAttr('disabled').removeClass('disabled');
		} else {
			theInput.attr('disabled', true).addClass('disabled');
		}
	});
	
	jQuery('#sms-legal').cluetip({
		activation: 'click', 
		width: 500,
		titleAttribute: '',
		dropShadow: false,
		cluetipClass: 'rounded',
		arrows: true
	});
	jQuery('.info-adicional').cluetip({
		activation: 'click', 
		width: 250,
		titleAttribute: '',
		dropShadow: false,
		cluetipClass: 'rounded',
		arrows: true
	});
	
	jQuery('.info-adicional-llarg').cluetip({
		activation: 'click', 
		width: 535,
		titleAttribute: '',
		dropShadow: false,
		cluetipClass: 'rounded',
		arrows: true
	});
	
});

// Functions for loading reasons (HOME)
function reasonsBefore() { 
	var reasonN = jQuery(this).find('.reason-number').text();
	var reasonT = jQuery(this).find('.reason-title').text();
	var reasonTx = jQuery(this).find('.reason-text').text();
	
	$('#reason-number').fadeOut('fast', function() {
		jQuery(this).text(reasonN).fadeIn('fast');
		Cufon.refresh();
	});
	$('#reason-title').fadeOut('fast', function() {
		jQuery(this).text(reasonT).fadeIn('fast');
		Cufon.refresh();
	});
	$('#reason-text p:first').slideUp('normal', function() {
		jQuery(this).text(reasonTx).slideDown('normal');
	});
	//console.log(this)
}
// Carga de videos
function applylinevar (a) {
	linevar = a;
}
