
function intval (mixed_var, base) {

    var tmp;

	

    var type = typeof(mixed_var);
     if (type === 'boolean') {
        return +mixed_var;
    } else if (type === 'string') {
        tmp = parseInt(mixed_var, base || 10);
        return (isNaN(tmp) || !isFinite(tmp)) ? 0 : tmp;    } else if (type === 'number' && isFinite(mixed_var)) {
        return mixed_var | 0;
    } else {
        return 0;
    }}


$(document).ready(function(){
	
/* 
	$('div.text').each(function() {		


		switch ($(this).parent().parent().parent().attr('class'))
		{
			case "wide4": 
			{
				$(this).parent().find('img.box').css('width','140px');
				$(this).css('width','140px');
				break;
			}
			case "wide3":
			{
				$(this).css('width','200px');
				break;			
			}
			case "wide2":
			{
				$(this).css('width','320px');
				break;			
			}		

		};

	});
	

	$('div.box_').each( function() {
		$(this).css('height',$(this).parent().parent().height());
		var _height = $(this).height() - $(this).find('img').height() - intval($(this).find('div.text').css('padding-top')) - intval($(this).find('div.text').css('padding-bottom')) -1;
		$(this).find('div.text').css('height',_height);
		$(this).append('<div class="bl"></div>');
	});

	$('.box_').mouseover(function() {
		var img_hover = $(this).find('img.box').attr('rel');
		var img_normal = $(this).find('img.box').attr('src');
		$(this).find('img.box').attr('src',img_hover);
		$(this).find('img.box').attr('rel',img_normal);

	});
	$('.box_').mouseout(function() {
		var img_hover = $(this).find('img.box').attr('rel');
		var img_normal = $(this).find('img.box').attr('src');
		$(this).find('img.box').attr('src',img_hover);
		$(this).find('img.box').attr('rel',img_normal);

	}); */

	
	prepareSelects($('body'),250);
	prepareInputs();
	
	$('div.encyclopedia div.desc').each(function(){
		$(this).css('display','block');
		this.origHeight = $(this).height();
		this.origPadding = ($(this).innerHeight() - this.origHeight) / 2;
		$(this).css('height',0).css('display','none');
	});
	
	$('div.encyclopedia ul.theme > li > a').bind('click',function(e){
		e.preventDefault();
		
		$parentLi = $(this).closest('li');
		$descDiv = $(this).siblings('div.desc');
		
		if ($parentLi.hasClass('selected')) {
			var o = $descDiv;
			$descDiv.stop().animate({height:0,paddingTop:0,paddingBottom:0},300,function(){o.css('display','none');});
			$parentLi.removeClass('selected');
		} else {
			var descDiv = $descDiv.get(0);
			$descDiv.css('display','block').stop().animate({height:descDiv.origHeight,paddingTop:descDiv.origPadding,paddingBottom:descDiv.origPadding},300);
			$parentLi.addClass('selected');
		}
	}).css('outline','none');
	
	$('div.encyclopedia ul.theme a.button-theme').bind('click',function(e){
		$parentLi = $(this).closest('li');
		$descDiv = $(this).closest('div.desc');
		
		$descDiv.stop().animate({height:0,paddingTop:0,paddingBottom:0},300,function(){$descDiv.css('display','none');});
		$parentLi.removeClass('selected');
		
		e.preventDefault();
	});
	$('.powieksz').attr('rel', 'nyro');	
	$('a[rel=nyro]').nyroModal({
		processHandler: function(settings) {
			var from = settings.from;
			if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
				$.nyroModalSettings({
					type: 'swf',
					height: 355,
					width: 425,
					url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
				});
			}
		}
	});
	
	$('div[id^=google-maps]').each(function(){
		var latLng = this.id.split(':');
		var myLatLng = new google.maps.LatLng(latLng[1], latLng[2]);
		var myOptions = {
		  zoom: 15,
		  center: myLatLng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		this.mapObj = new google.maps.Map(this,myOptions);
		
		var marker = new google.maps.Marker({
			position: myLatLng,
			map: this.mapObj,
			icon: '/images/google-marker.png'
		});
	});
	
	function getNewHeight($obj) {
		oldHeight = $obj.height();
		oldPosition = $obj.css('position');
		$obj.css('position','absolute').css('height','auto');
		newHeight = $obj.height();
		$obj.css('position',oldPosition).css('height',oldHeight);
		
		return newHeight;
	}
	$('a[rel^=expandable]').bind('click',function(e){
		e.preventDefault();
		var objId = this.rel.split(':')[1];
		var $obj = $('#'+objId).stop();
		
		if ($obj.hasClass('expandable-hidden')) {
			$obj.animate({'opacity':1,'height':getNewHeight($obj)+"px"},300,function(){
				$(this).css('overflow','').css('opacity','').css('height','');
			}).removeClass('expandable-hidden');
		}
		else
			$obj.animate({'opacity':0,'height':"0px"},300,function(){$(this).css('overflow','hidden');}).css('overflow','hidden').addClass('expandable-hidden');
	
		$(this).siblings('span').removeClass('display-none');
		$(this).remove();		
	});
	$('input[class^=expandable]').bind('change',function(e){
		var objId = this.className.split(' ')[0].split(':')[1];
		var $obj = $('#'+objId).stop();
		
		if (!(this.type == "radio" && objId == "null")) {
			if (this.checked) {
				$obj.animate({'opacity':1,'height':getNewHeight($obj)+"px"},300,function(){
					$(this).css('overflow','').css('opacity','').css('height','');
				}).removeClass('expandable-hidden');
			}
			else {
				$obj.animate({'opacity':0,'height':"0px"},300,function(){$(this).css('overflow','hidden');}).css('overflow','hidden').addClass('expandable-hidden');
			}
		}
		
		if (this.type == "radio") {
			$('input[name='+this.name+']',this.form).not(this).each(function(){
				var objId = this.className.split(':')[1];
				$('#'+objId).stop().animate({'opacity':0,'height':"0px"},300,function(){$(this).css('overflow','hidden');}).css('overflow','hidden').addClass('expandable-hidden');
			});
		}
		
		$('a[rel=expandable:'+objId+']').children().toggle();
		e.preventDefault();
	});
	$('.expandable-hidden').each(function(){
		$(this).css('opacity',0);
		$('input[class=expandable:'+this.id+']').attr('checked',false);
	});
	
	$(".fileinputs #file_1").change(function(){
		$("#fakeField_1").val($(this).val());
	s});

	$(".fileinputs #file_2").change(function(){
		$("#fakeField_2").val($(this).val());
	}); 
	
});
