// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
    arguments.callee = arguments.callee.caller;
    var newarr = [].slice.call(arguments);
    (typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
  }
};

// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());

// place any jQuery/helper plugins in here, instead of separate, slower script files.



/*
* Title: BlueMouse Custom Scripts
* Author: Yves Torres
* Standard Scripts
*/


/*
* prepare external links
*/

(function externalLinks() {	
	$('a.blank,a[rel^="blank"]').attr('target','_blank');
})(document); 

/*
* set & get Cookies 
*/

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var name_eq = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(name_eq) == 0) return c.substring(name_eq.length,c.length);
	}
	return null;
}

/*
* ghostVal
*/

function ghostVal() {
	if(!Modernizr.input.placeholder){
		$('input[placeholder]').each(function(){
			var el = this;
			$(el).attr('value',$(el).attr('placeholder'));
			$(el).data('txt',$(el).attr('placeholder'));
			
			if($(el).attr('type')=='password') {
				repField = "<input onfocus=\"replaceField(this,'"+$(el).attr('id')+"')\" type=\"text\" value=\""+txt+"\" id=\""+$(el).attr('id')+"\" style=\""+$(el).attr('style')+"\" maxlength=\""+$(el).attr('maxlength')+"\" name=\""+$(el).attr('name')+"\" />";
				orgField = "<input onblur=\"replaceField(this,'"+$(el).attr('id')+"')\" type=\"password\" value=\"\" id=\""+$(el).attr('id')+"\" style=\""+$(el).attr('style')+"\" maxlength=\""+$(el).attr('maxlength')+"\" name=\""+$(el).attr('name')+"\" />";
				$(el).replaceWith(repField);
			}
			
			else {
				$(el).bind('focus',function() { 
					if($(this).attr('value')==$(el).data('txt')) {
						$(this).attr('value',''); 
					}
				});
				$(el).bind('blur',function() { 
					if($(this).attr('value')=='') {
					$(this).attr('value',$(el).data('txt')); 
					}
				});
			}
			
		});
	}
}

/*
* Animations
*/

function animations(){
}

/*
* Calendars
*/

function calendars(){
	var aDay = 86400000, a=new Date(), options = {constrainInput:true,showOn: 'both', buttonImage: './files/images/ico-calendar.png',minDate: a, buttonImageOnly: true, prevText:'&laquo;',nextText:'&raquo;',showOtherMonths:true,selectOtherMonths:true,showMonthAfterYear:false,defaultDate:a,showOptions:{direction:'right'},dateFormat:'dd.mm.yy'}
	if($('#checkin-date').length>0){
		var checkIn = $('#checkin-date'), checkOut = $('#checkout-date'),
		checkEnd = function(){
			var vDate=checkIn.datepicker('getDate').valueOf()+(aDay), newDate=new Date(vDate); 		
			checkOut.datepicker('option','minDate',newDate);
		}
		$.datepicker.setDefaults($.extend(options,$.datepicker.regional['de']));
		checkIn.datepicker({onSelect: function() { checkEnd(); } });
		checkOut.datepicker();
		if(checkIn.val())checkEnd();
	}
	if($('#res_date').length>0){
		$.datepicker.setDefaults($.extend(options,$.datepicker.regional['de']));
		$('#res_date').datepicker();
	}
}

/*
* superSizeBgs
*/

function superSizeBgs(){
	if(!$('#header').hasClass('gallery')){
		$.supersized({
			slides:vars.bgImgs,
			slideShow:0,
			image_protect:0,
			performance:2,
			keyboard_nav:0,
			vertical_center:0
		});
	} else {
		$.supersized({
			slides:vars.bgImgs,
			autoplay:0,
			image_protect:0,
			performance:2,
			vertical_center:1,
			horizontal_center:1
		});
	}
}

function cufon(){
	Cufon.replace('.cufon');
}
		
$(document).ready(function(){
	superSizeBgs();
	cufon();
	calendars();
	ghostVal();
});
