
jQuery.log = function(message) { if(window.console) { console.debug(message); } else { alert(message);}};

jQuery.fn.kubSlide = function(settings) {

	var settings = jQuery.extend({
		slideshow : 1,
		slide_interval : 5000

	}, settings);

	return this.each(function() {

		var $panel = $(this);
		var $current = $panel.find('.active');
		var slideshow_interval = 0;
		var project = $current.attr('id');
		var color = '#fff';
		var url = 'project.php';


		move = function (){
			//$.log(project);
			$('.project').each(function (i,el){
				if( project == $(el).attr('id')){
					//$.log(i);
					//$("div.scroll").scrollable().move(i);
				}
			});
		}

		next = function (){
			$current.fadeOut('fast').removeClass('active');
			$current  = ($current.next().size() > 0) ? $current.next() : $('#projects .project:first');
			show($current);
			move();
		};

		prev = function (){
			$current.fadeOut('fast').removeClass('active');
			$current  = ($current.prev().size() > 0) ? $current.prev() : $('#projects .project:last');
			show($current);
			move();
		};

		show = function ($current){

			project = $current.attr('id');
			//var url = 'works/' + project + '.html';
			$.ajax({
				beforeSend: function(){
					$('#'+project +' .inner_project .harea').append('loading').end().css({'width':'500px','margin':'0 auto'});
				},
				error: function(){
					//$.log('error call '+url);
				},
				async: false,
				cache: true,
				url: url,
				type: "POST",
				data:'project=' + project,
				success: function(data){
					$current.fadeIn(600).addClass('active');
					var metadata = $('.active').metadata();
					if ( metadata.color){
						color = metadata.color;
						background = metadata.background;
					}
					//$.log(background);
					//$('#'+project).css({'background-image':'url(public/images/' + background + '.jpg)'});
					//$('body').css('background','#BFBFBF');

					$('#'+project +' .inner_project .harea').html(data);
					if(settings.slideshow) {
						$('#'+project +' .harea').hover(function(){
							clearInterval(slideshow_interval);
						}, function() {
							clearInterval(slideshow_interval);
							slideshow_interval = setInterval(next, settings.slide_interval);
						});
					}
				}
			});

		};

		$('.left a').click(function(){
			if(slideshow_interval) {
				clearInterval(slideshow_interval);
				slideshow_interval = setInterval(prev, settings.slide_interval);
			}
			$current.fadeIn();
			prev();

			return false;
		});
		$('.right a').click(function(){
			if(slideshow_interval) {
				clearInterval(slideshow_interval);
				slideshow_interval = setInterval(next, settings.slide_interval);
			}
			$current.fadeIn();
			next();
			return false;
		});
		$('.inner_project').html('<div class="harea"></div>');
		if(settings.slideshow == 1) slideshow_interval = setInterval(next, settings.slide_interval);
		show($current);
		$(".items div img").click(function(){
			project = $(this).attr('alt');
			$current.fadeIn();
			$current.fadeOut().removeClass('active');
			//$.log($current);
			$current = $panel.find('#'+project);
			//$.log($current);
			show($current);
		})

	});
};

(function(c){c.tools=c.tools||{version:{}};c.tools.version.tooltip="1.0.2";var b={toggle:[function(){this.getTip().show()},function(){this.getTip().hide()}],fade:[function(){this.getTip().fadeIn(this.getConf().fadeInSpeed)},function(){this.getTip().fadeOut(this.getConf().fadeOutSpeed)}]};c.tools.addTipEffect=function(d,f,e){b[d]=[f,e]};c.tools.addTipEffect("slideup",function(){var d=this.getConf();var e=d.slideOffset||10;this.getTip().css({opacity:0}).animate({top:"-="+e,opacity:d.opacity},d.slideInSpeed||200).show()},function(){var d=this.getConf();var e=d.slideOffset||10;this.getTip().animate({top:"-="+e,opacity:0},d.slideOutSpeed||200,function(){c(this).hide().animate({top:"+="+(e*2)},0)})});function a(f,e){var d=this;var h=f.next();if(e.tip){if(e.tip.indexOf("#")!=-1){h=c(e.tip)}else{h=f.nextAll(e.tip).eq(0);if(!h.length){h=f.parent().nextAll(e.tip).eq(0)}}}function j(k,l){c(d).bind(k,function(n,m){if(l&&l.call(this)===false&&m){m.proceed=false}});return d}c.each(e,function(k,l){if(c.isFunction(l)){j(k,l)}});var g=f.is("input, textarea");f.bind(g?"focus":"mouseover",function(k){k.target=this;d.show(k);h.hover(function(){d.show()},function(){d.hide()})});f.bind(g?"blur":"mouseout",function(){d.hide()});h.css("opacity",e.opacity);var i=0;c.extend(d,{show:function(q){if(q){f=c(q.target)}clearTimeout(i);if(h.is(":animated")||h.is(":visible")){return d}var o={proceed:true};c(d).trigger("onBeforeShow",o);if(!o.proceed){return d}var n=f.position().top-h.outerHeight();var k=h.outerHeight()+f.outerHeight();var r=e.position[0];if(r=="center"){n+=k/2}if(r=="bottom"){n+=k}var l=f.outerWidth()+h.outerWidth();var m=f.position().left+f.outerWidth();r=e.position[1];if(r=="center"){m-=l/2}if(r=="left"){m-=l}n+=e.offset[0];m+=e.offset[1];h.css({position:"absolute",top:n,left:m});b[e.effect][0].call(d);c(d).trigger("onShow");return d},hide:function(){clearTimeout(i);i=setTimeout(function(){if(!h.is(":visible")){return d}var k={proceed:true};c(d).trigger("onBeforeHide",k);if(!k.proceed){return d}b[e.effect][1].call(d);c(d).trigger("onHide")},e.delay||1);return d},isShown:function(){return h.is(":visible, :animated")},getConf:function(){return e},getTip:function(){return h},getTrigger:function(){return f},onBeforeShow:function(k){return j("onBeforeShow",k)},onShow:function(k){return j("onShow",k)},onBeforeHide:function(k){return j("onBeforeHide",k)},onHide:function(k){return j("onHide",k)}})}c.prototype.tooltip=function(d){var e=this.eq(typeof d=="number"?d:0).data("tooltip");if(e){return e}var f={tip:null,effect:"slideup",delay:30,opacity:1,position:["top","center"],offset:[0,0],api:false};if(c.isFunction(d)){d={onBeforeShow:d}}c.extend(f,d);this.each(function(){e=new a(c(this),f);c(this).data("tooltip",e)});return f.api?e:this}})(jQuery);
(function(b){b.tools=b.tools||{version:{}};b.tools.version.scrollable="1.0.5";var c=null;function a(p,m){var s=this;if(!c){c=s}function n(t,u){b(s).bind(t,function(w,v){if(u&&u.call(this,v.index)===false&&v){v.proceed=false}});return s}b.each(m,function(t,u){if(b.isFunction(u)){n(t,u)}});var d=!m.vertical;var f=b(m.items,p);var j=0;function l(u,t){return u.indexOf("#")!=-1?b(u).eq(0):t.siblings(u).eq(0)}var q=l(m.navi,p);var g=l(m.prev,p);var i=l(m.next,p);var h=l(m.prevPage,p);var o=l(m.nextPage,p);b.extend(s,{getIndex:function(){return j},getConf:function(){return m},getSize:function(){return s.getItems().size()},getPageAmount:function(){return Math.ceil(this.getSize()/m.size)},getPageIndex:function(){return Math.ceil(j/m.size)},getRoot:function(){return p},getItemWrap:function(){return f},getItems:function(){return f.children()},getVisibleItems:function(){return s.getItems().slice(j,j+m.size)},seekTo:function(w,u,A){if(u===undefined){u=m.speed}if(b.isFunction(u)){A=u;u=m.speed}if(w<0){w=0}if(w>s.getSize()-m.size){return s}var B=s.getItems().eq(w);if(!B.length){return s}var t={index:w,proceed:true};b(s).trigger("onBeforeSeek",t);if(!t.proceed){return s}if(d){var v=-B.position().left;f.animate({left:v},u,m.easing,A?function(){A.call(s)}:null)}else{var z=-B.position().top;f.animate({top:z},u,m.easing,A?function(){A.call(s)}:null)}if(q.length){var x=m.activeClass;var y=Math.ceil(w/m.size);y=Math.min(y,q.children().length-1);q.children().removeClass(x).eq(y).addClass(x)}if(w===0){g.add(h).addClass(m.disabledClass)}else{g.add(h).removeClass(m.disabledClass)}if(w>=s.getSize()-m.size){i.add(o).addClass(m.disabledClass)}else{i.add(o).removeClass(m.disabledClass)}c=s;j=w;b(s).trigger("onSeek",{index:w});return s},move:function(v,u,t){var w=j+v;if(m.loop&&w>(s.getSize()-m.size)){w=0}return this.seekTo(w,u,t)},next:function(u,t){return this.move(1,u,t)},prev:function(u,t){return this.move(-1,u,t)},movePage:function(v,u,t){return this.move(m.size*v,u,t)},setPage:function(x,y,v){var u=m.size;var t=u*x;var w=t+u>=this.getSize();if(w){t=this.getSize()-m.size}return this.seekTo(t,y,v)},prevPage:function(u,t){return this.setPage(this.getPageIndex()-1,u,t)},nextPage:function(u,t){return this.setPage(this.getPageIndex()+1,u,t)},begin:function(u,t){return this.seekTo(0,u,t)},end:function(u,t){return this.seekTo(this.getSize()-m.size,u,t)},reload:function(){return r()},click:function(u,x,v){var w=s.getItems().eq(u);var t=m.activeClass;if(u<0||u>=this.getSize()){return s}if(m.size==2){if(u==s.getIndex()){u--}s.getItems().removeClass(t);w.addClass(t);return this.seekTo(u,x,v)}if(!w.hasClass(t)){s.getItems().removeClass(t);w.addClass(t);var z=Math.floor(m.size/2);var y=u-z;if(y>s.getSize()-m.size){y=s.getSize()-m.size}if(y!==u){return this.seekTo(y,x,v)}}return s},onBeforeSeek:function(t){return n("onBeforeSeek",t)},onSeek:function(t){return n("onSeek",t)}});if(b.isFunction(b.fn.mousewheel)){p.bind("mousewheel.scrollable",function(u,v){var t=b.browser.opera?1:-1;s.move(v>0?t:-t,50);return false})}g.addClass(m.disabledClass).click(function(){s.prev()});i.click(function(){s.next()});o.click(function(){s.nextPage()});h.addClass(m.disabledClass).click(function(){s.prevPage()});if(m.keyboard){b(document).unbind("keydown.scrollable").bind("keydown.scrollable",function(t){var u=c;if(!u||t.altKey||t.ctrlKey){return}if(d&&(t.keyCode==37||t.keyCode==39)){u.move(t.keyCode==37?-1:1);return t.preventDefault()}if(!d&&(t.keyCode==38||t.keyCode==40)){u.move(t.keyCode==38?-1:1);return t.preventDefault()}return true})}function r(){if(q.is(":empty")||q.data("me")==s){q.empty();q.data("me",s);for(var u=0;u<s.getPageAmount();u++){var v=b("<"+m.naviItem+"/>").attr("href",u).click(function(x){var w=b(this);w.parent().children().removeClass(m.activeClass);w.addClass(m.activeClass);s.setPage(w.attr("href"));return x.preventDefault()});if(u===0){v.addClass(m.activeClass)}q.append(v)}}else{var t=q.children();t.each(function(w){var x=b(this);x.attr("href",w);if(w===0){x.addClass(m.activeClass)}x.click(function(){q.find("."+m.activeClass).removeClass(m.activeClass);x.addClass(m.activeClass);s.setPage(x.attr("href"))})})}if(m.clickable){s.getItems().each(function(x,w){var y=b(this);if(!y.data("set")){y.bind("click.scrollable",function(){s.click(x)});y.data("set",true)}})}if(m.hoverClass){s.getItems().hover(function(){b(this).addClass(m.hoverClass)},function(){b(this).removeClass(m.hoverClass)})}return s}r();var e=null;function k(){if(e){return}e=setInterval(function(){if(m.interval===0){clearInterval(e);e=0;return}s.next()},m.interval)}if(m.interval>0){p.hover(function(){clearInterval(e);e=0},function(){k()});k()}}b.fn.scrollable=function(d){var e=this.eq(typeof d=="number"?d:0).data("scrollable");if(e){return e}var f={size:5,vertical:false,clickable:true,loop:false,interval:0,speed:400,keyboard:true,activeClass:"sel",disabledClass:"disabled",hoverClass:null,easing:"swing",items:".items",prev:".prev",next:".next",prevPage:".prevPage",nextPage:".nextPage",navi:".navi",naviItem:"a",api:false,onBeforeSeek:null,onSeek:null};b.extend(f,d);this.each(function(){e=new a(b(this),f);b(this).data("scrollable",e)});return f.api?e:this}})(jQuery);
// custom easing called "kslide"
$.easing.kslide = function (x, t, b, c, d) {
	var s = 1.70158;
	if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
	return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
}

function map() {
	// Create a map object
	var size = new YSize(380,265);
	var map = new YMap(document.getElementById('google_map'),YAHOO_MAP_REG,size);
	var geoPoint = new YGeoPoint(44.439133,26.105189);
	map.addOverlay(new YMarker(geoPoint));
	// Add map type control
	map.addTypeControl();
	// Add map zoom (long) control
	map.addZoomLong();
	// Add the Pan Control
	map.addPanControl();
	// Display the map centered on a geocoded location
	map.drawZoomAndCenter(geoPoint, 2);

}


$(document).ready(function(){

    //$('body').addClass('loader');
	$(window).bind("load", function(){

		//map();
        $('body').css('background-image','none');
		$('#projects').kubSlide();


		$('.current_page').slideDown();
		$('#home, #logo').click(function(){
			$('.page').slideUp();
			$('#inner_content').next().removeClass('current_page');
			$('#menu ul li a').removeClass('current');
			$('#menu ul li a:first').addClass('current');
			return false;
		});
		$('#menu ul li a').not('#facebook a,#twitter a,#blog a').click(function(ev){
			if($(this).is('.current')) return false;

			$('#menu ul li a').removeClass('current');
			$(this).addClass('current');
			var sel = $(this).attr('href');
			$('.current_page').slideUp('400', function () {
				$(this).removeClass('current_page');
				$(sel).slideDown('400').addClass('current_page');
			});
			ev.stopPropagation();
			ev.preventDefault();
			return false;
		});


		$("div.scroll").scrollable({easing: 'kslide', speed: 700});
		$(".items div img").each(function (i,el) {

			var project = $(this).attr('src').split('/')[4].replace(/.jpg/, "");
			$(this).attr('alt',project);
			//$.log(project);
		});

		$(".member").tooltip({position: ['top', 'right'], offset: [80, -65] });
		$(".member2").tooltip({	position: ['top', 'left'], 	offset: [80, 100] });
/*
		$('.accordion li a.selected').next().show();
		$('.accordion li a:last').css('border','none');
		$('.accordion li a').click(function(ev){
			$('.selected').removeClass('selected').next().slideUp();
			$(this).not('.selected').addClass('selected').next().slideDown();
			ev.stopPropagation();
			return false;
		});
*/

		$('a.email').each(function(){
			e = this.rel.replace('/','@');
			this.href = 'mailto:' + e;
			$(this).text(e);
		});

	});
});
