//2do tydle dve funkce jako jquery pluginy
function log(arg) {
	console.log(arg);
}

function global(name, val) {
	var prefix = 'globalvar_';
	if(val) {
		//set
		$('body').data(prefix+name, val);
	} else {
		//get
		return $('body').data(prefix+name);
	}
}

var flash = false;

$(document).ready(function() {
	//hlasky
	$('ul.error').wrap('<div id="flashes"></div>');

	var flashes = $('div#flashes');

	if(flashes.length) {
		var cl = flashes.clone();
		flashes.remove();

		$(document.body).prepend(cl);

		$('div#flashes').hide().addClass('jqmWindow')
		.prepend('<a href="#" class="jqmClose">X</a>').jqm().jqmShow();
	}

	/*
	function contentLoad() {
		$('label.required').css('font-style', 'normal').append(' *')
	}

	contentLoad();
	*/

	//Cufon.replace('div#left ul a, div#left h2, div#mainContact h2, div#mainContact span', {fontFamily: 'helvetica', hover: true});

	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_rounded', social_tools: ''});

	//$('div#changer').createFader(4000);

	//global('faderId', 'topImages');
	
	var posterId = 'postersCont';
	
	if($('div#'+posterId).length) {
			
		var flashvars = {
				'xmlinput': baseUrl+lang+'/xml/posters/'
		};
		
		var params = {
				menu: 'false',
				scale: 'noscale',
				wmode: 'transparent'
		};
		
		var attributes = {
				id: posterId,
				name: posterId
		};
			
		swfobject.embedSWF(baseUrl+'swf/imageroller.swf', posterId, 882, 161, '9.0.0', baseUrl+'swf/expressInstall.swf', flashvars, params, attributes, function(event){
			if(event.success)flash = true;
		});
	}
	
var copterId = 'copter';
	
	if($('div#'+copterId).length) {
		var copterFlashId = 'copterFlash';
		
		$('div#'+copterId).after('<div id="'+copterFlashId+'"></div>').remove();
			
		var flashvars = {
				'xmlinput': baseUrl+lang+'/xml/copter/'
		};
		
		var params = {
				menu: 'false',
				scale: 'noscale',
				wmode: 'transparent'
		};
		
		var attributes = {
				id: copterFlashId,
				name: copterFlashId
		};
			
		swfobject.embedSWF(baseUrl+'swf/vrtulniq.swf', copterFlashId, 304, 200, '9.0.0', baseUrl+'swf/expressInstall.swf', flashvars, params, attributes);
	}
	
	var playerId = 'player';
	
	if($('div#'+playerId).length) {
		
		var playerFlashId = 'playerFlash';		
		var mp3 = $('div#'+playerId+' span').html();
		
		$('div#'+playerId).html('<div id="'+playerFlashId+'"></div>');
			
		var flashvars = {
				'file': mp3,
				'as': 1				
		};
		
		var params = {
				menu: 'false',
				scale: 'noscale',
				wmode: 'transparent'
		};
		
		var attributes = {
				id: playerFlashId,
				name: playerFlashId
		};
			
		swfobject.embedSWF(baseUrl+'swf/niftyplayer.swf', playerFlashId, 165, 37, '9.0.0', baseUrl+'swf/expressInstall.swf', flashvars, params, attributes);
	}
		
	/* 
	 
	//contactMap
	var contactMap = $('div#contactMap');
	if(contactMap.length) {
		var mapOptions = {
			zoom: 15,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var CMap = new google.maps.Map(contactMap.get(0), mapOptions);

		var geocoder = new google.maps.Geocoder();
		var address = $('span#address').html()+' '+$('span#city').html();

		geocoder.geocode({'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				CMap.setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
					map: CMap,
					position: results[0].geometry.location
				});
			}
		});
	}
	*/
});

$(window).load(function(){	
	if(flash == false) {
		var posters = $('div#posters');
		
		posters.addClass('noFlash');
		var wid = 0;
		$('div#postersCont img.poster').each(function(){
			wid += $(this).width() + 17;
		});
		
		$('div#postersCont').width(wid);
		
		var passBook = $('a#passBook');		
		var pos = passBook.position();
		
		posters.get(0).scrollLeft = pos.left;
	}
});

