﻿String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}

String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

var ajaxContent = 'tresc';
var show_hide_delay = 600;

var IE = document.all ? true : false;
var IE7 = false;
if (!IE)
	document.captureEvents(Event.MOUSEMOVE)
var tempX = 0;
var tempY = 0;

var ajaxIndicator;
var ajaxIndicatorCounter = 0;

 
function doChangeName(name){
	//alert("ala ma kota1");
	$("#projectHover").html(name);
}

function removeName(){
	$("#projectHover").html("");
} 
 
 
function getMouseXY(e) {
	if (IE7) {
		tempX = event.clientX + document.documentElement.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;
	}
	else if (IE) { // grab the x-y pos.s if browser is IE

		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}
	ajaxIndicator.style.left = (tempX+10) + 'px';
	ajaxIndicator.style.top = (tempY+16) + 'px';
	return true;
}

function makeGalleryIfExists(){
	$('#myGallery').each( function () {
		var myGallery = new gallery(Moo.$('myGallery'), {
			timed: false,
			embedLinks: false,
			delay: 6000,
			textShowCarousel: 'Wybierz zdjęcie',
			carouselMaximizedOpacity: 0.9,
			showInfopane: false
		});
	});
	$('#startGallery').each( function () {
		var myGallery = new gallery(Moo.$('startGallery'), {
			timed: true,
			embedLinks: false,
			delay: 6000,
			showArrows: false,
			showCarousel: false,
			textShowCarousel: 'Wybierz zdjęcie',
			carouselMaximizedOpacity: 0.9,
			showInfopane: true
		});
	});
	 
}

$(document).ready(function() {
	ajaxIndicator = document.getElementById('ajax_indicator');
	document.onmousemove = getMouseXY;
	if (IE && parseInt(jQuery.browser.version) >= 7)
		IE7 = true;
	$.ajaxSetup({
		url: "index.php",
		async: true,
		type: "GET",
		success: function(data) {
			//alert('SUCCESS3:'+data);
			$('#'+ajaxContent).html(data);
			makeGalleryIfExists();

		},
		error: function(data) {
			alert('ERROR:'+data);
			//alert(data);
		},
		timeout: function(data) {
			alert('TIMEOUT:'+data);
			//alert(settings);
		},
		beforeSend: function(data) {
			//alert('beforeSend');
			ajaxIndicator.style.display='block';
			ajaxIndicatorCounter++;
		},
		complete: function(data) {
			ajaxIndicatorCounter--;
			if (ajaxIndicatorCounter < 1)
				ajaxIndicator.style.display='none';
			//alert('complete');
		}
	});
	
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	/*
	$("ul.topnav li span").click(function() { //When trigger is clicked...
	
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	*/
	
	/*
	$("ul.topnav li span").hover(function() { 
			//Following events are applied to the subnav itself (moving subnav up and down)
			$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

			$(this).parent().hover(
				function() {
				}, 
				function(){	
				$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			});
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	*/
	
	$("ul.topnav li").hover(function() { 
			//Following events are applied to the subnav itself (moving subnav up and down)
			$(this).find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

			$(this).hover(
				function() {
				}, 
				function(){	
				$(this).find("ul.subnav").hide().slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
			});
			//$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			//$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	$('a[@rel=ajaxed]').livequery('click', function(event) { 
	
		url='s=' + $(this).attr("href").substring($(this).attr("href").lastIndexOf("/")+1).replace('?','&') +'&ajaxed=true';
		//alert("x"+url);
		$.ajax({
			data: url
		});
	
		return false;
	});
	
	$("#nav-one li").hover(
			function(){ $("ul", this).fadeIn("fast"); }, 
			function() { } 
	);
	
	$("img.icon")
        .mouseover(function() { 
			var src = $(this).attr("src").replace("_b", "");
            $(this).attr("src", src);
			//alert("out");
			doChangeName($(this).attr("alt"));
        })
        .mouseout(function() {
            var src = $(this).attr("src").match(/[^\.]+/) + "_b.jpg";
            $(this).attr("src", src);
			//alert("over");
			removeName();
        });

	
	if (document.all) {
			$("#nav-one li").hoverClass ("sfHover");
	};
	//$('#'+ajaxContent).hide();
	//makeGalleryIfExists();	
	//$('#'+ajaxContent).show();
	//alert('ready2');
})



	  
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};	  


$(document).ready(function(){


});


