$(document).ready(function() {

	/**** _target="blank" ****/
	var buff, temp;
	buff = $("a").map(function() { return $(this); });
	jQuery.each(buff, function(index, value) {
		temp = value.attr('href');
		if (temp != undefined) {
			temp = temp.replace(/http:\/\//, '');
			temp = temp.split('/');
			if (temp[0].lastIndexOf('javascript') == -1 && temp[0].lastIndexOf('#') == -1 && temp[0] != window.location.host) value.attr('target', '_blank');
		}
	});

	if (start) {
		/**** preloader ****/
		var ima = new Array('menu_brandy_hq3.png', 'menu_brandy_hybrid.png', 'menu_brandy_snaz.png', 'menu_grupa_indiv_filozofia.png', 'menu_grupa_indiv_partnerzy.png', 'menu_grupa_indiv_materialy.png', 'tlo2.png', 'loading.gif');
		for(var i = 0; i < ima.length; ++i) {
			temp = ima[i];
			ima[i] = new Image();
			ima[i].src = base+'tpl/pl/szablon1/img/'+temp;
		}
	}

	/**** menu ****/
	$('#in_top_menu li').hover(
		function() {
			$(this).find('div.jq-menu:hidden').show(0);
		},
		function() {
			$(this).find('div.jq-menu:visible').hide(0);
		}
	);

	/**** slider ****/
	var temp = $(".slider div");
	jQuery.each(temp, function() {
		slider.push(this);
	});
	if (slider[0]) pause = window.setTimeout("fa1()", 3000);
	$('.slider_minus').click(function() {
		fa3();
		--iny;
		if (iny) iny = 0;
		if (!fade) fa1();
	});
	$('.slider_plus').click(function() {
		fa3();
		++iny;
		try {
			if (!slider[iny]) iny = 0;
		}
		catch(e) {
			iny = 0;
		}
		if (!fade) fa1();
	});
	$('.slider_num').click(function() {
		fa3();
		iny = $(this).text();
		--iny;
		try {
			if (!slider[iny]) iny = 0;
		}
		catch(e) {
			iny = 0;
		}
		if (!fade) fa1();
	});

	/**** Thickbox ****/

	tb_init('a.thickbox');

	/**** fade ****/

	$(".realizacje_back1").click(function() {
		var src = $("#imig").attr("src");
		src = src.split('_');
		src.pop();
		src = src.join('_');
		if ($(this).hasClass('maxi1')) src += '_1.jpg'; else src += '_2.jpg';
		$("#imig").fadeOut(1000, function() {
			$("#loader").fadeIn(200, function() {
				$("#imig").attr("src", src);
				var imgg = document.getElementById('imig');
				imgg.onload = InitFade;
			});
		});
	});

	/**** end ****/

});

function InitFade() {
	$("#loader").fadeOut(200, function() {
		$("#imig").fadeIn(1000);
	});
}

/**** slider ****/

var slider = new Array();
var fade = 0;
var animate = true;
var iny = 1;
var aktualnie = 0;
var pause;
function fa1() {
	fade = 1;
	$(slider[aktualnie]).fadeOut(1000, function() {
		fade = 0;
		fa2();
	});
};
function fa2() {
	try {
		if (!slider[iny]) iny = 0;
	}
	catch(e) {
		iny = 0;
	}
	aktualnie = iny;
	var temp = $('.slider_num');
	jQuery.each(temp, function() {
		if ($(this).text() == (iny+1)) $(this).css({'color': '#ffffff'}); else $(this).css({'color': '#424242'});
	});

	fade = 1;
	$(slider[iny]).fadeIn(1000, function() {
		fade = 0;
		++iny;
		pause = window.setTimeout("fa1()", 4000);
	});
};
function fa3() {
	window.clearTimeout(pause);
}

/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
 *
 * Modified by Micha³ Grabania
*/

function tb_init(domChunk){
	$(domChunk).click(function(){
		tb_show(this.href);
		this.blur();
		return false;
	});
}
function tb_show(url) {
	try {
		if (typeof document.body.style.maxHeight === "undefined") {
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow", "hidden");
			if (document.getElementById("TB_HideSelect") === null) {
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		} else {
			if (document.getElementById("TB_overlay") === null) {
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		if (tb_detectMacXFF()) $("#TB_overlay").addClass("TB_overlayMacFFBGHack"); else $("#TB_overlay").addClass("TB_overlayBG");
		$("body").append("<div id='TB_load'><img src='"+base+"tpl/pl/szablon1/img/loading.gif' /></div>");
		$('#TB_load').show();
		var baseURL;
		if (url.indexOf("?") !== -1) baseURL = url.substr(0, url.indexOf("?")); else baseURL = url;

		TB_WIDTH = 692;
		TB_HEIGHT = 335;
		ajaxContentW = TB_WIDTH - 30;
		ajaxContentH = TB_HEIGHT - 45;

		if($("#TB_window").css("display") != "block") {
			$("#TB_window").append("<div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
		} else {
			$("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
			$("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
			$("#TB_ajaxContent")[0].scrollTop = 0;
		}
		$("#TB_ajaxContent").load(url += ",ajax?random=" + (new Date().getTime()),function(){
			tb_position();
			$("#TB_load").remove();
			tb_init("#TB_ajaxContent a.thickbox");
			$("#TB_window").css({display:"block"});
		});
		document.onkeyup = function(e){ 	
			if (e == null) keycode = event.keyCode; else keycode = e.which;
			if (keycode == 27) tb_remove();
		};
	} catch(e) { }
}
function tb_position() {
	$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if (!(jQuery.browser.msie && jQuery.browser.version < 7)) $("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
}
function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}
function tb_detectMacXFF() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) return true;
}
function tb_remove() {
	$("#TB_imageOff").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = '';
	document.onkeyup = '';
}

