﻿$(function(){
	$('#cv td').each(function(){
		$(':checkbox', this).appendTo($(this).next('td'));
	});
	$('#cv .legalnote').text('Wyrażam zgodę na przetwarzanie moich danych osobowych zawartych w mojej ofercie pracy dla potrzeb niezbędnych do realizacji procesu rekrutacji (zgodnie z ustawą z dnia 29.08.1997 r. o ochronie danych osobowych Dz.U. Nr 133 poz. 883).');
	
	$('#zone-login :text:first').focus();
	
	if ($('#zakard').size()) {
		$('<div id="pattern"><img src="/pub/uploadimages/pattern-zloty.jpg" /></div>').css({height: '287px'}).appendTo('#article .col:last');
		$('#zakard, #zloty, #camel, #korektor, #dzieciecy, #primo, #srebrny').each(function() {
			$this = $(this);
			$this.wrap('<a href="#' + $this.attr('id') + '"></a>').click(function(event) {
				$('#pattern').html('<img />');
				$('#pattern img').hide().attr('src', '/pub/uploadimages/pattern-' + $(this).attr('id') + '.jpg').fadeIn('slow');
				event.preventDefault();
			});
		});
	}

	function thisMovie(movieName) {
		if (navigator.appName.indexOf("Microsoft") != -1)
			return window[movieName];
		else
			return document[movieName];
	};
	
	$('#games li a').click(function(event){
		window.open(this.href, 'game', 'toolbar=no,width=750,height=570');
		event.preventDefault();
	});
	
	$('#opinions').show().find('ul a').click(function(event){
		$this = $(this);
		thisMovie("opinion").loadFile({file: '/pub/uploadflash/'+ $this.attr('href').substr(1) +'.flv'});
		thisMovie("opinion").sendEvent('playpause');
		$('#opinions a').removeClass('active');
		$this.addClass('active');
		event.preventDefault();
	});
	
	$('#opinions li a:first').addClass('active');

	if ($('#tv').size()) {
		var so = new SWFObject("/pub/uploadflash/mediaplayer.swf", "opinion", "265", "232", "8", "");
		so.addVariable("height", "232");
		so.addVariable("width", "265");
		so.addVariable("file", "/pub/uploadflash/" + $('#opinions li a:first').attr('href').substr(1) + ".flv");
		so.addVariable("image", "/pub/uploadimages/tv-bg.jpg");
		so.addVariable("enablejs", "true");
		so.addVariable("javascriptid", "opinion");
		so.addParam("allowscriptaccess", "always");
		so.addParam("allowfullscreen", "true");
		so.write("tv");
	}
	
	//lightbox
	if ($('.gallery li a').size()) {
		$('.gallery li a').lightBox();
	}
	//GOOGLE MAPS
	if ($('#map').size()) {
		$('#map').css({height: '360px'});
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		var myIcon = new GIcon(G_DEFAULT_ICON);
		myIcon.image = "/pub/uploadimages/marker.png";
		var gmarkers = [];
		bounds = new GLatLngBounds();
		$('#article .latlng').each(function(index){
			var center = GLatLng.fromUrlValue($(this).val().slice(1, -1));
			marker = new GMarker(center, {icon: myIcon, title: $('#map-entries > li:eq(' + index + ') h3').text()});
			gmarkers.push(marker);
			GEvent.addListener(marker, "click", function() {
				gtxContent = $('#map-entries > li:eq(' + index + ') .short-content').html();
				if (gtxContent == '')
					gtxContent = $('#map-entries > li:eq(' + index + ') .content').html();
				this.openInfoWindowHtml('<div class="info-window"><h3>' + $('#map-entries > li:eq(' + index + ') h3').text() + '</h3>' + gtxContent + '</div>');
			});
			$('#map-entries > li:eq(' + index + ') h3').wrapInner('<a href="#content"></a>').click(function(){
				GEvent.trigger(gmarkers[index], 'click');
			});
			bounds.extend(marker.getPoint());
			map.setCenter(center);
			map.addOverlay(marker);
		});
		map.setZoom(map.getBoundsZoomLevel(bounds));
		map.setCenter(bounds.getCenter());
	}
	
});