function start() {
	if(typeof kkStart=='function') kkStart();
	if(konkursForm) {
		$('yccform').onsubmit = '';
		swfuStart();
	}
	
	if(typeof kkForm!='undefined'&&kkForm!=null&&kkForm) {
		swfuKKStart();
	}
}
window.onload = start;

//swfupload
var konkursForm = false;
var swfu;
function swfuStart() {
	swfu = new SWFUpload({
		// Backend Settings
		upload_url: "swfupload.php",
		post_params: {"PHPSESSID": $F('sess')},

		// File Upload Settings
		file_size_limit : "100 MB",	// 2MB
		file_types : "*.jpg;*.flv;*.avi;*.mpg;*.jpeg;*.gif;*.png,*.pdf,*.mp4,*.mov",
		file_types_description : "Film lub obraz",
		file_upload_limit : "1",

		// Event Handler Settings - these functions as defined in Handlers.js
		//  The handlers are not part of SWFUpload but are part of my website and control how
		//  my website reacts to the SWFUpload events.
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,

		// Button Settings
		button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png",
		button_placeholder_id : "spanButtonPlaceholder",
		button_width: 180,
		button_height: 18,
		button_text : '<span class="button">Wybierz plik <span class="buttonSmall">(max. 100 MB)</span></span>',
		button_text_style : '.button {  font-family:trebuchet MS,helvetica,sans-serif;font-size: 12pt; border:1px solid #252525;	color:#aaaaaa;	} .buttonSmall { font-size: 10pt; }',
		button_text_top_padding: 0,
		button_text_left_padding: 18,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
		button_cursor: SWFUpload.CURSOR.HAND,
		
		// Flash Settings
		flash_url : "images/swfupload.swf",

		custom_settings : {
			upload_target : "divFileProgressContainer"
		},
		
		// Debug Settings
		debug: false
	});
};
//nowa galeria
var aktGal = new Galeria();
function showGal(el) {
	aktGal.initGal(el);
}

function textMaxLen(inputId,counterId,maxlimit) {
	if($(inputId).value.length > maxlimit) $(inputId).value = $(inputId).value.substring(0, maxlimit);
	$(counterId).update(maxlimit - $(inputId).value.length);
}

function viewportDims() {
	var viewportwidth;
	var viewportheight;
	//simplest method
	var dim = document.viewport.getDimensions();
	if(dim.height>0&&dim.width>0) {
		viewportwidth = dim.width;
		viewportheight = dim.height;
	}
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	else if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth,
		viewportheight = window.innerHeight
	}
 	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'&& typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0) {
		viewportwidth = document.documentElement.clientWidth,
		viewportheight = document.documentElement.clientHeight
	}
	// older versions of IE
	else {
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
	return {width:viewportwidth,height:viewportheight};
}
var rssChan=0;
function toggleRss() {
	if (rssChan==0) {
		Effect.BlindDown('rssChannels', { duration: 0.5 });
		Effect.Fade('arr', { duration: 0.5 });
		rssChan=1;
	}
	else {
		Effect.BlindUp('rssChannels', { duration: 0.5 });
		Effect.Appear('arr', { duration: 0.5 });		
		rssChan=0;
	}
}	
function bannerFadeOut() {
	Effect.Fade('banner_ankieta_2010', { duration: 0.3 });
}


function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=350,screenX=150,screenY=150,top=150,left=50');
}

function fbs_click() { 
	u=location.href;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
	}
	

function basename (path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}
	
	
function image_small_maker(orig_width, orig_height, max_width, max_height) {
	var xRatio = max_width / orig_width; 
	var yRatio = max_height / orig_height; 
	var new_width = 0;
	var new_height = 0;
	if ( (orig_width <= max_width) && (orig_height <= max_height) ) { 
	 new_width = orig_width; 
	 new_height = orig_height; 
	} 
	else if ((xRatio * orig_height) < max_height) { 
	 new_height = Math.ceil(xRatio * orig_height); 
	 new_width = max_width; 
	} 
	else { 
		new_width = Math.ceil(yRatio * orig_width); 
		new_height = max_height; 
		}
	var output = [];
	output.push(Math.round(new_width));
	output.push(Math.round(new_height));
	return output;
}
	
	
	
	
var okno = null;
function window_open(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus();
  okno = null;
}
function window_open_scroll(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus()
}




function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function basename (path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}




function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}
