function redirect(url,timer) {
	if(timer==null)
		timer=5000;
	
	setTimeout(function(){
		document.location.href=url;
	},timer);
}

function addNivoSlider() {
	$('#slider').nivoSlider({
		directionNav: false, 
		controlNav: false, 
		effect:'fade',//effect:'random',
		slices:15,
		boxCols: 8,
		boxRows: 4,
		animSpeed: 500,
		pauseTime: 10000,
		beforeChange: function(){
			/* console.log($('#slider').data('nivo:vars').currentSlide);
			console.log($('#slider').data('nivo:vars').currentImage); */
		},
		afterChange: function(){
			/* console.log($('#slider').data('nivo:vars').currentSlide);
			console.log($('#slider').data('nivo:vars').currentImage); */
		},
		afterLoad: function(){
			/* console.log($('#slider').data('nivo:vars').currentSlide);
			console.log($('#slider').data('nivo:vars').currentImage); */
		}
	});
}

function addRotateLogo() {
	var image = document.getElementById('image');
	var canvas = document.getElementById('canvas');
	var canvasContext = canvas.getContext('2d');
	
	var angle = 0;
	function convertToRadians(degree) {
		return degree*(Math.PI/180);
	}
	
	function incrementAngle() {
		angle++;
		if(angle > 360) {
			angle = 0;
		}
	}
	
	function drawRandomlyColoredRectangle() {
		canvasContext.clearRect(-(canvas.width / 2), -(canvas.height / 2), canvas.width, canvas.height);
		incrementAngle();
		canvasContext.save();
		canvasContext.rotate(convertToRadians(angle));
		canvasContext.drawImage(image, -(canvas.width / 2), -(canvas.height / 2));
		canvasContext.restore();
	}
	
	canvasContext.translate((canvas.width / 2),(canvas.height / 2));
	setInterval(drawRandomlyColoredRectangle, 30);
}

function preloadBanners() {
    var img = $(".nivoSlider img");
    var loaded = 0;
    var count = img.length;
	
	if(count>1) {
		img.each(function(i) {
			var tempSrc = $(this).attr("src");
			$(this).attr("src", "");

			jQuery(this).load(function() {
				loaded++;
				
				if (count == loaded) {
					addNivoSlider();
					$(".nivoSlider").css({
						display: "none",
						visibility: "visible"
					}).fadeIn(500);
				}
			}).attr("src", tempSrc);
		});
	} else if(count==1) {
		$(".nivoSlider").css({
			display: "none",
			visibility: "visible"
		}).fadeIn(500);
	} else {
		$(".nivoSlider").parent().css({
			background: "#FFFFFF" 
		}).fadeIn(500);
	}
}

function preloadPortfolioList() {
    var img = $(".portfoliBoxImg img");
    var loaded = 0;
    var count = img.length;
	
	img.each(function(i) {
		var tempSrc = $(this).attr("src");
		$(this).attr("src", "");

		jQuery(this).load(function() {
			$(this).css({
				/* display: "none", */
				visibility: "visible"/* ,  */
			})/* .fadeIn(500) */;
		}).attr("src", tempSrc);
	});
}

function preloadPortfolioShow() {
    var img = $(".projectImg .boxImg img");
    var loaded = 0;
    var count = img.length;
	
	img.each(function(i) {
		var tempSrc = $(this).attr("src");
		$(this).attr("src", "");

		jQuery(this).load(function() {
			$(this).css({
				/* display: "none", */
				visibility: "visible"/* ,  */
			})/* .fadeIn(500) */;
		}).attr("src", tempSrc);
	});
}

function addTargetBlank() {
	$(".targetBlank").click(function(){
		this.target = "_blank";
	});
}

/* function addWysiwyg(){
	var opts = {
		cssClass : 'el-rte',
		height   : 450,
		toolbar  : 'maxi'
	}
	$('#long').elrte(opts);
} */


/* function addWysiwyg(layer,toolbar){
	var opts = {
		cssClass 	: "el-rte",
		height   	: 250,
		toolbar  	: toolbar,
		allowSource	: false
	}
	$(layer).elrte(opts);
} */

/* function addImgCropping(x1,x2,y1,y2,id) {
	$("img#" + id + "")
		.imgAreaSelect({
			remove: true, 
			handles: true
		});
	
	$("img#" + id + "").imgAreaSelect({
			x1: x1,
			y1: y1,
			x2: x2,
			y2: y2,
			resizable: false, 
			handles: true, 
			persistent: true, 
			borderWidth: 2, 
			borderColor1: '#FF0000', 
			instance: true, 
			onSelectEnd: function(img, selection) {
				$("input[name='x1']").val(selection.x1);
				$("input[name='x2']").val(selection.x2);
				$("input[name='y1']").val(selection.y1);
				$("input[name='y2']").val(selection.y2);
			} 
	});
	
	$('input[name=delThumb]').unbind('click').bind('click',function(){
		$("img#" + id + "").imgAreaSelect({
			remove: true
		});
		
		$("#imageMin").html("");
		$("input[name='imgUpload']").val("");
		$("input[name='error']").val("");
		
		return false;
	});
} */


/* function sortableGalleries(url) {
	$("#sortable").sortable({
		items: 'tr.ui-state-default',
		stop: function(event, ui) {
			$("#communicate span").css({ display: "none" });
			$("#communicate #_c_1").css({ display: "block" });
			$("#communicate").css({ display: "block" });
			
			sortArray = $("#sortable").sortable("toArray");
			
			$.ajax({
				type: "POST",
				url: url + "sortuj/",
				data : {"sortArray": sortArray},
				async: false,
				success: function(data, textStatus, jqXHR){
					$("#communicate #_c_1").css({ display: "none" });
					$("#communicate #_c_2").css({ display: "block" });
					
					setTimeout(function(){
						$("#communicate span").css({ display: "none" });
						$("#communicate").css({ display: "none" });
					},1500);
				},
				error: function(jqXHR, textStatus, errorThrown) {
					$("#communicate #_c_1").css({ display: "none" });
					$("#communicate #_c_3").css({ display: "block" });
					
					setTimeout(function(){
						$("#communicate span").css({ display: "none" });
						$("#communicate").css({ display: "none" });
					},1500);
				}
			});
		}
	});
} */


/* function sortablephotos(url,record) {
	$("#sortable").sortable({
		items: 'tr.ui-state-default',
		stop: function(event, ui) {
			$("#communicate span").css({ display: "none" });
			$("#communicate #_c_1").css({ display: "block" });
			$("#communicate").css({ display: "block" });
			
			sortArray = $("#sortable").sortable("toArray");
			
			$.ajax({
				type: "POST",
				url: url + "sortuj/" + record + "/",
				data : {"sortArray": sortArray},
				async: false,
				success: function(data, textStatus, jqXHR){
					$("#communicate #_c_1").css({ display: "none" });
					$("#communicate #_c_2").css({ display: "block" });
					
					setTimeout(function(){
						$("#communicate span").css({ display: "none" });
						$("#communicate").css({ display: "none" });
					},1500);
				},
				error: function(jqXHR, textStatus, errorThrown) {
					$("#communicate #_c_1").css({ display: "none" });
					$("#communicate #_c_3").css({ display: "block" });
					
					setTimeout(function(){
						$("#communicate span").css({ display: "none" });
						$("#communicate").css({ display: "none" });
					},1500);
				}
			});
		}
	});
} */

//nadanie pluginu na linki do okienka wyswietlajacego google maps
function showImages() {
	$(".prettyPhoto").prettyPhoto({
		theme: "dark_rounded",
		overlay_gallery: false, 
		social_tools: ""
	});
}





function portfolioImg() {
	$(".portfoliBoxInfo")
		.mouseover(function(){
			$(this).stop().fadeTo(150,1);
		})
		.mouseout(function(){
			$(this).stop().fadeTo(150,0.01);
		});
}









/* 
function checkFormSubmit(id) {
	$("#"+id).val("1");
}

// Funkcje Google Maps
var geocoder;
var map;


//Funckja inicjalizuje mape Google Maps
function initialize(layer) {
	try {
		geocoder = new google.maps.Geocoder();
		var myOptions = {
			zoom: 13,
			center: new google.maps.LatLng(50.664113997454905,19.040079399999968),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		
		map = new google.maps.Map(document.getElementById(layer),myOptions);
	} catch(exception) {
		
	}
}


//Funckja odpowiada za dodanie punktu na mape Google Maps
function addOverlays(coordinatesX,coordinatesY){
	try {
		var marker = new google.maps.Marker({
			map: map,
			position: new google.maps.LatLng(coordinatesX,coordinatesY)
		});
	} catch(exception) {
		
	}
} */


function showPanel(){
	$(".socialFacebook")
		.hover(function() {
			$(this).stop(true, false).animate({ right: "310" }, "medium");
		}, function() {
			$(this).stop(true, false).animate({ right: "0" }, "medium");
		}, 500);
}




// Funkcje Google Maps
var geocoder = new Object();
var map = new Object();
var markersArray = [];
var bounds = null;
var objects = 0;

function initialize(id) {
	
	try {
		geocoder = new google.maps.Geocoder();
		var myOptions = {
			zoom: 6,
			center: new google.maps.LatLng(51.629805, 19.237883),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		
		map = new google.maps.Map(document.getElementById(id),myOptions);
		bounds = new google.maps.LatLngBounds();
	} catch(e) {}
}

function addOverlays(coordinatesX,coordinatesY){
	
	if(coordinatesX.length>0 && coordinatesY.length>0) {
		++objects;
		
		try {
			map.setCenter(new google.maps.LatLng(coordinatesX,coordinatesY));
			var marker = new google.maps.Marker({
				map: map,
				position: new google.maps.LatLng(coordinatesX,coordinatesY)
			});
			//map.setZoom(12);
			//markersArray = marker;
			
			
			bounds.extend(new google.maps.LatLng(coordinatesX,coordinatesY));
			map.setCenter(bounds.getCenter());
			
			//gdy ilosc obiektow jest wieksza od 1, 
			//wielkosc i powiekszenie mapy dopasowane zostaje do dodanych markerow
			if(objects>1) map.fitBounds(bounds);
		} catch(e) {}
	}
	
}

function delAttachmentsButton(){
	$("input[name='delete']").unbind('click').bind('click',function(){
		$(this).parent().remove();
		
		return false;
	});
}

function addAttachmentsButton() {
	$("input[name='add']").click(function(){
		if ($('.uploadifyQueueItem').length == 0) {
			$("input[name='send']").click();
		} else {
			$("#file_upload").uploadifyUpload();
		}
		
		return false;
	});
}

function checkFormSubmit(id) {
	$("#"+id).val("1");
}









