/**
* Javascipt // JQuery
* internal script
* for: 'Crocus City Hall'
* Webway company - 2011
*/

document.documentElement.className = document.documentElement.className.replace(/\bno_js\b/,'') + ' js';

// Decodes emails (see /contacts/) encoded with base64
function base64_decode(data) {
	var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var o1, o2, o3, h1, h2, h3, h4, bits, i=0, enc='';

	do {
		h1 = b64.indexOf(data.charAt(i++));
		h2 = b64.indexOf(data.charAt(i++));
		h3 = b64.indexOf(data.charAt(i++));
		h4 = b64.indexOf(data.charAt(i++));

		bits = h1<<18 | h2<<12 | h3<<6 | h4;

		o1 = bits>>16 & 0xff;
		o2 = bits>>8 & 0xff;
		o3 = bits & 0xff;

		if (h3 == 64)	  enc += String.fromCharCode(o1);
		else if (h4 == 64) enc += String.fromCharCode(o1, o2);
		else			   enc += String.fromCharCode(o1, o2, o3);
	} while (i < data.length);

	return enc;
}

jQuery(document).ready(function(){
	
	//background image
	/*----------------------------------------------------------------------------------------------------*/

	var theWindow = $(window),
		$bg = $("#bg"),
	//	aspectRatio = $bg.width() / $bg.height(),
		minWidth = 980;

	function resizeBg() {
	//	if ( (theWindow.width() / theWindow.height()) < aspectRatio ) $bg.removeClass().addClass('bgheight');
	//	else $bg.removeClass().addClass('bgwidth');		
	
		$bg.removeClass().addClass('bgwidth');

		if (theWindow.width() < minWidth) $bg.addClass('bgminwidth');
	}

	theWindow.bind('resize', resizeBg).trigger('resize');
	
	//calendar show
	/*----------------------------------------------------------------------------------------------------*/	

	var 
		calendar = $('#calendar'),
		calendarContent = calendar.find('.calendar_content'),
		calendarTrigger = calendar.children('a.calendar'),
		calendarClose = calendar.find('.calendar_content a.calendar'),
		calendarCloseCross = calendar.find('a.close');

	if(calendar.length){
		calendarTrigger.click(function(){calendarContent.removeClass('getout'); return false;});
		calendarClose.click(function(){calendarContent.addClass('getout'); return false;});
		calendarCloseCross.click(function(){calendarContent.addClass('getout'); return false;});
	}


	//crocus carousel
	/*----------------------------------------------------------------------------------------------------*/

	if ($('.rotator-slide').length){

		//hide/show arrows
		$('.arrow_carousel').addClass('getout');
		if ($('.rotator-slide').length > 1) 
			$('.arrow_carousel').removeClass('getout');

		//initialize carousel
		$('#crocus-carousel').crocusCarousel({

			animateVal : 900,
			keyboard : true,
			animateEasing : 'easeInOutQuad',

			arrowNext : $('.arrow_carousel_next'),
			arrowPrev : $('.arrow_carousel_prev'),
			
			slideHeight : 211,
			slideWidth : 880,
			
			scaleSecond : 0.9438,
			opacitySecond : 0.35,		
			bottomFirst : '45px',

			scaleInit : 0.8591,
			opacityInit : 0.65,
			bottomSecond : '22px'

		});
				
	}		
});
