
Slider = {
	obj:null, timeouts:0, pos:0,
	SetObj:function(inobj) {
		Slider.obj = inobj;
	},
	Start:function(start) {
		if(Slider.obj.length>1){
			Slider.pos = 0;
			$(Slider.obj).eq(0).fadeOut(800,function(){ $(Slider.obj).eq(1).fadeIn(800,Slider.Slide); })
		}
	},
	Slide:function() {
		if(Slider.obj.length>1){
			Slider.timeout = window.setTimeout( function() {
				if(Slider.obj.length>1){
					Slider.obj.eq( Slider.pos++ ).fadeOut(800,function() {
						if(Slider.pos == Slider.obj.length){ Slider.pos = 0; };									   
						if(Slider.obj.length>1){
							Slider.obj.eq( Slider.pos ).fadeIn(800,Slider.Slide);
						}
					});
				}
			},1600);
		}else{
			Slider.timeout = null
		}
	},
	Stop:function() {
		if(Slider.obj.length>1){
			Slider.timeout=0;
			window.clearTimeout(Slider.timeout);
			var tempobj = Slider.obj;
			Slider.SetObj({});
			tempobj.fadeOut(800,function() {
				tempobj.eq(0).fadeIn(800);
			});
		}
	}
};


SliderV2 = {
	c:[],
	next:function(u){
		SliderV2.c[u].a = SliderV2.c[u].o.filter('.active');
		if (SliderV2.c[u].a.length == 0 ){ SliderV2.c[u].a = SliderV2.c[u].o.filter(':last'); }
		SliderV2.c[u].n =  SliderV2.c[u].a.next().length ? SliderV2.c[u].a.next() : SliderV2.c[u].o.filter(':first');
		SliderV2.c[u].a.addClass('last-active').animate({opacity:0}, 500, function() {
			SliderV2.c[u].n.css({opacity: 0.0}).addClass('active').animate({opacity:1}, 500, function() { SliderV2.c[u].a.removeClass('active last-active'); });
		});
	},
	start:function(obj,d){
		var u = SliderV2.c.length;
		if(d>0){ nd=d; }else{ nd=4000; }
		SliderV2.c[u] = { a:null, n:null, o:null, t:null, d:nd };
		var $o = $(obj);
		SliderV2.c[u].o = $o;
		//$("#news").hover(function(){ window.clearInterval(SliderV2.c[u].t); },function(){ SliderV2.t = window.setInterval("SliderV2.c["+u+"].next()", 4000 ); });
		//SliderV2.c[u].t = window.setInterval("SliderV2.next("+u+")", 4000 );
		SliderV2.resume(u)
		return u;
	},
	pause:function(u){
		window.clearInterval(SliderV2.c[u].t);
	},
	resume:function(u){
		SliderV2.c[u].t = window.setInterval("SliderV2.next("+u+")", SliderV2.c[u].d );
	},
	pauseAll:function(){
		for(var i=0,m=SliderV2.c.length;i<m;i+=1){
			window.clearInterval(SliderV2.c[i].t);
		}
	},
	resumeAll:function(){
		for(var i=0,m=SliderV2.c.length;i<m;i+=1){
			SliderV2.c[i].t = window.setInterval("SliderV2.next("+i+")", SliderV2.c[i].d );
		}
	}
};
	
	
SliderV3 = {
	c:[],
	next:function(u){
		SliderV3.c[u].a = SliderV3.c[u].o.filter('.active');
		if (SliderV3.c[u].a.length == 0 ){ SliderV3.c[u].a = SliderV3.c[u].o.filter(':last'); }
		SliderV3.c[u].n =  SliderV3.c[u].a.next().length ? SliderV3.c[u].a.next() : SliderV3.c[u].o.filter(':first');
		SliderV3.c[u].a.addClass('last-active').animate({opacity:0}, 500, function() {
			SliderV3.c[u].n.css({opacity: 0.0}).addClass('active').animate({opacity:1}, 500, function() { SliderV3.c[u].a.removeClass('active last-active'); });
		});
	},
	start:function(obj,op){
		var u = SliderV3.c.length;
		SliderV3.c[u] = { a:null, n:null, o:null, t:null, d:2000 };
		var $o = $(obj);
		SliderV3.c[u].o = $o;
		$(op).hover(function(){ SliderV3.resume(u); SliderV3.next(u) },function(){ SliderV3.pause(u); });
		//SliderV2.c[u].t = window.setInterval("SliderV2.next("+u+")", 4000 );
		//SliderV3.resume(u)
		return u;
	},
	pause:function(u){
		window.clearInterval(SliderV3.c[u].t);
	},
	resume:function(u){
		SliderV3.c[u].t = window.setInterval("SliderV3.next("+u+")", SliderV3.c[u].d );
	},
	pauseAll:function(){
		for(var i=0,m=SliderV3.c.length;i<m;i+=1){
			window.clearInterval(SliderV3.c[i].t);
		}
	},
	resumeAll:function(){
		for(var i=0,m=SliderV3.c.length;i<m;i+=1){
			SliderV3.c[i].t = window.setInterval("SliderV3.next("+i+")", SliderV3.c[i].d );
		}
	}
};
	
	
	$(function() {
	 	$("body").addClass("js");
	
	/*$(window).bind('load resize',function(){
		$t = $("#container")
		$t.css({"position":"absolute"})
		if($(window).width()<$t.width()){
			$t.css({"marginLeft":"0px","left":"0px"})
		}else{
			var marginleft = "-"+String($t.width()/2)+"px"
			$t.css({"marginLeft":marginleft,"left":"50%"})
		}
	});*/
	
	home_slide_news = {
	a:null,
	n:null,
	o:null,
	t:null,
	next:function(){
		home_slide_news.a = home_slide_news.o.filter('.active');
		if (home_slide_news.a.length == 0 ){ home_slide_news.a = home_slide_news.o.filter(':last'); }
		home_slide_news.n =  home_slide_news.a.next().length ? home_slide_news.a.next() : home_slide_news.o.filter(':first');
		home_slide_news.a.addClass('last-active').animate({opacity:0}, 500, function() {
			home_slide_news.n.css({opacity: 0.0}).addClass('active').animate({opacity:1}, 500, function() { home_slide_news.a.removeClass('active last-active'); });
		});
	},
	start:function(){
		var $o = $("#news > ul li");
		home_slide_news.o = $o;
		$("#news").hover(function(){ window.clearInterval(home_slide_news.t); },function(){ home_slide_news.t = window.setInterval("home_slide_news.next()", 4000 ); });
		home_slide_news.t = window.setInterval("home_slide_news.next()", 4000 );
	}
};
	
	
	if ($.browser.msie && $.browser.version < 7) {
		$("img[src$='.png']").ifixpng();
		$('#logo_tab a').ifixpng();
	}
	
	$("a[title^='New Window: ']").each(function(){
		var newtitle = String($(this).attr('title')).substr(String("New Window: ").length)
		$(this).attr('title',newtitle).click(function() {
			var newwin = window.open(this.href,"newwindow");
			newwin.focus();
			return false;
		});
	});
	/*
	var testimonials= 0, $testimonials;
	function testimonialsfn(){
		window.setTimeout(function(){
			$testimonials.eq( testimonials++ ).fadeOut(800, function(){
				if(testimonials == $testimonials.length){ testimonials = 0; }
				$testimonials.eq( testimonials ).fadeIn(800, testimonialsfn )
			})
		},1600);
	};
	$testimonials = $("#testimonials_tab a span.testimonial");
	$testimonials.hide()
	$testimonials.eq(testimonials).fadeIn(800, testimonialsfn );
	*/
	image_gallery_col1 = SliderV2.start("#content div.image_gallery div.column1 li");
	image_gallery_col2 = SliderV2.start("#content div.image_gallery div.column2 li");
	image_gallery_col3 = SliderV2.start("#content div.image_gallery div.column3 li");
	image_gallery_col4 = SliderV2.start("#content div.image_gallery div.column4 li");
	
	testimonials = SliderV2.start("#testimonials_tab li",6000);
	
	
	$("#content div.img_container").each(function(){
		var $obj = $(this);
		SliderV3.start($obj.find('li'),$obj);
	});
	
	$("div.project div.img_container a img").each(function() {
		$(this).css({position:"absolute",top:"50%",left:"50%",marginLeft:"-"+($(this).width()/2)+"px",marginTop:"-"+($(this).height()/2)+"px"});
	});
	$("div.image_gallery div a img").each(function() {
		$(this).css({position:"absolute",top:"50%",left:"50%",marginLeft:"-"+($(this).width()/2)+"px",marginTop:"-"+($(this).height()/2)+"px"});
	});
	
	$("a[rel='image_gallery']").colorbox({transition:'fade', slideshow:true, speed:500,width:"95%", height:"95%",onOpen:function(){ SliderV2.pauseAll(); },onClosed:function(){ SliderV2.resumeAll(); } });
	 
	/*
	var imcol1= 0, $imcol1;
	function imcol1fn(){
		window.setTimeout(function(){
			$imcol1.eq( imcol1++ ).fadeOut(800, function(){
				if(imcol1 == $imcol1.length){ imcol1 = 0; }
				$imcol1.eq( imcol1 ).fadeIn(800, imcol1fn )
			})
		},2400);
	};
	$imcol1 = $("div.image_gallery div.column1 img");
	if($imcol1.length>1){
		$imcol1.hide()
		$imcol1.eq(imcol1).fadeIn(800, imcol1fn );
	}
	
	var imcol2= 0, $imcol2;
	function imcol2fn(){
		window.setTimeout(function(){
			$imcol2.eq( imcol2++ ).fadeOut(800, function(){
				if(imcol2 == $imcol2.length){ imcol2 = 0; }
				$imcol2.eq( imcol2 ).fadeIn(800, imcol2fn )
			})
		},2400);
	};
	$imcol2 = $("div.image_gallery div.column2 img");
	if($imcol2.length>1){
		$imcol2.hide()
		$imcol2.eq(imcol2).fadeIn(800, imcol2fn );
	}
	
	var imcol3= 0, $imcol3;
	function imcol3fn(){
		window.setTimeout(function(){
			$imcol3.eq( imcol3++ ).fadeOut(800, function(){
				if(imcol3 == $imcol3.length){ imcol3 = 0; }
				$imcol3.eq( imcol3 ).fadeIn(800, imcol3fn )
			})
		},2400);
	};
	$imcol3 = $("div.image_gallery div.column3 img");
	if($imcol3.length>1){
		$imcol3.hide()
		$imcol3.eq(imcol3).fadeIn(800, imcol3fn );
	}
	
	var imcol4= 0, $imcol4;
	function imcol4fn(){
		window.setTimeout(function(){
			$imcol4.eq( imcol4++ ).fadeOut(800, function(){
				if(imcol4 == $imcol4.length){ imcol4 = 0; }
				$imcol4.eq( imcol4 ).fadeIn(800, imcol4fn )
			})
		},2400);
	};
	$imcol4 = $("div.image_gallery div.column4 img");
	if($imcol4.length>1){
		$imcol4.hide()
		$imcol4.eq(imcol4).fadeIn(800, imcol4fn );
	}
	*/
	
	/*
	$("div.project div.img_container a").hover(
		function() {
			$pis = $(this).children("img");
			var pis= $pis.index( $("img[class!='nd']")[0] );
			Slider.SetObj($pis);
			Slider.Start(pis);
		},
		function() {
			Slider.Stop();
		}
	).click(function() { return false; });
	
	$("div.project div.img_container a img").each(function() {
		$(this).css({position:"absolute",top:"50%",left:"50%",marginLeft:"-"+($(this).width()/2)+"px",marginTop:"-"+($(this).height()/2)+"px"});
	});
	$("div.image_gallery div a img").each(function() {
		$(this).css({position:"absolute",top:"50%",left:"50%",marginLeft:"-"+($(this).width()/2)+"px",marginTop:"-"+($(this).height()/2)+"px"});
	});
	*\/
	
	
	PreviewBox = {
		$obj:null,
		$parent:null,
		index:0,
		total:0,
		$background:$("<div id=\"modal-background\">&nbsp;</div>").css({position:"fixed",opacity:0.4,width:"100%",height:"100%",top:0,left:0,background:"#000",zIndex:9996,display:"none"}),
		$img_background:$("<div id=\"modal-img_background\">&nbsp;</div>").css({position:"fixed",width:"804px",height:"604px",top:"50%",left:"50%",marginLeft:"-402px",marginTop:"-302px",background:"#fff url(images/loading.gif) center no-repeat",zIndex:9997,display:"none", border:"1px #777 solid"}),
		$controls_bg:$("<div id=\"modal-controls\"></div>").css({position:"fixed",width:"806px",marginLeft:"-403px",height:"684px",top:0,left:0,background:"none",zIndex:9998,display:"none"}),
		$controls_title:$("<div id=\"modal-controls-title\"><span>&nbsp;</span></div>"),
		$controls_count:$("<div id=\"modal-controls-count\"><span>&nbsp;</span></div>"),
		$controls_exit:$("<a href=\"#\" id=\"modal-controls-exit\"></a>"),//.css({position:"absolute",width:"100px",height:"30px",top:0,right:0,background:"#ccc",zIndex:9998,display:"block"}),
		$controls_exit_span:$("<span>Exit [ X ]</span>"),//.css({display:"inline",fontSize:"14px"}),
		$controls_next:$("<a href=\"#\" id=\"modal-controls-next\"></a>"),//.css({position:"absolute",width:"100px",height:"30px",bottom:0,right:0,background:"#ccc",zIndex:9998,display:"block",padding:"10px",border:"1px #777 solid"}),
		$controls_next_span:$("<span>Next [ &raquo; ]</span>"),//.css({display:"inline",fontSize:"14px"}),
		$controls_prev:$("<a href=\"#\" id=\"modal-controls-prev\"></a>"),//.css({position:"absolute",width:"100px",height:"30px",bottom:0,left:0,background:"#ccc",zIndex:9998,display:"block",padding:"10px",border:"1px #777 solid"}),
		$controls_prev_span:$("<span>[ &laquo; ] Previous</span>"),//.css({display:"inline",fontSize:"14px"}),
		Init:function() {
			PreviewBox.$background.appendTo("body");
			PreviewBox.$img_background.appendTo("body");
			PreviewBox.$controls_bg.appendTo("body");
			PreviewBox.$controls_title.appendTo(PreviewBox.$controls_bg);
			PreviewBox.$controls_count.appendTo(PreviewBox.$controls_bg);
			PreviewBox.$controls_exit.appendTo(PreviewBox.$controls_bg).click(function() { PreviewBox.Hide(); });
			PreviewBox.$controls_exit_span.appendTo(PreviewBox.$controls_exit);
			PreviewBox.$controls_next.appendTo(PreviewBox.$controls_bg).click(function() { PreviewBox.Next(); return false; });
			PreviewBox.$controls_next_span.appendTo(PreviewBox.$controls_next);
			PreviewBox.$controls_prev.appendTo(PreviewBox.$controls_bg).click(function() { PreviewBox.Prev(); return false; });
			PreviewBox.$controls_prev_span.appendTo(PreviewBox.$controls_prev);
			if($.browser.msie&&$.browser.version<7) {
				$("#modal-background").css({position:"absolute",opacity:0.4,width:"100%",height:"100%",overflow:"hidden",top:0,left:0,margin:0,background:"#000",zIndex:9997,display:"none"});
				$("#modal-img_background").css({position:"absolute",width:"804px",height:"604px",top:"50%",left:"50%",marginLeft:"-402px",marginTop:"-302px",background:"#fff url(images/loading.gif) center no-repeat",zIndex:9997,display:"none", border:"1px #777 solid"});
				$("#modal-img_background.loaded").css({backgroundImage:"none"});
				$("#modal-controls").css({position:"absolute",width:"806px",height:"632px",top:"50%",left:"50%",background:"none",zIndex:9998,display:"none",marginTop:"-316px",marginLeft:"-403px"});
				$("#modal-controls-title").css({position:"absolute",width:"674px",height:"14px",top:0,left:0,background:"#ddd",zIndex:9998,display:"block",border:"1px #777 solid",textAlign:"left"});
				$("#modal-controls-title span").css({padding:"2px", fontSize:"14px", fontWeight:"bold", display:"block"});
				$("#modal-controls-count").css({position:"absolute",width:"100px",height:"14px",bottom:0, fontSize:"14px",left:"50%",background:"#ddd",zIndex:9998,marginLeft:"-50px",display:"block",border:"1px #777 solid",textAlign:"center"});
				$("#modal-controls-count span").css({padding:"2px", display:"block"});
				$("#modal-controls-exit").css({position:"absolute",width:"120px",height:"14px",top:"0",right:"0",background:"#ddd",zIndex:9998,display:"block",border:"1px #777 solid",textAlign:"right"});
				$("#modal-controls-next").css({position:"absolute",width:"120px",height:"14px",bottom:"0",right:"0",background:"#ddd",zIndex:9998,display:"block",border:"1px #777 solid",textAlign:"right"});
				$("#modal-controls-prev").css({position:"absolute",width:"120px",height:"14px",bottom:"0",left:"0",background:"#ddd",zIndex:9998,display:"block",border:"1px #777 solid"});
				$("#modal-controls a").css({fontSize:"10px", color:"#000000", textDecoration:"none"}).hover(function() { $(this).css({background:"#bbb"}); },function() { $(this).css({background:"#ddd"}); });
				$("#modal-controls a span").css({padding:"2px", display:"block"});
				
				PreviewBox.$controls_bg.remove();
				
				
			}
		},
		HandleKeyDown:function(e) { 
			if(e.keyCode == 27) {
				// escape
				PreviewBox.Hide();
			}else if(e.keyCode == 38){
				// arrow up
				PreviewBox.Prev();
			}else if(e.keyCode == 40){
				// arrow down
				PreviewBox.Next();
			}else if(e.keyCode == 37){
				// arrow left
				PreviewBox.Prev();
			}else if(e.keyCode == 39){
				// arrow right
				PreviewBox.Next();
			}else if(e.keyCode == 13){
				// enter
				PreviewBox.Hide();
			}
		},
		Show:function(url,t,w,h,o,p) {
			if(typeof(o)!=="undefined"){
				PreviewBox.$obj = o;
				if(typeof(p)!=="undefined"){
					PreviewBox.$parent = p;
				}else{
					PreviewBox.$parent = PreviewBox.$obj.parent("a");
				}
				PreviewBox.index = PreviewBox.$parent.find("img").index(PreviewBox.$obj);
				PreviewBox.total = PreviewBox.$parent.find("img").length;
				PreviewBox.$controls_title.children("span").eq(0).text(t);
				PreviewBox.$controls_count.children("span").eq(0).text((PreviewBox.index+1)+" / "+PreviewBox.total);
			}
			if(PreviewBox.total>1){
				PreviewBox.$controls_count.show();
				PreviewBox.$controls_next.show();
				PreviewBox.$controls_prev.show();
			}else{
				PreviewBox.$controls_count.hide();
				PreviewBox.$controls_next.hide();
				PreviewBox.$controls_prev.hide();
			}
			PreviewBox.$background.fadeIn(500);
			var $image = $("<img id=\"modal-image\" />").css({position:"fixed",top:"50%",left:"50%",background:"none",border:"1px #ffffff solid",zIndex:9999,display:"none",width:w+"px", height:h+"px",marginLeft:"-"+(w/2)+"px",marginTop:"-"+(h/2)+"px"});
			if($.browser.msie&&$.browser.version<7) {
				//$image.css({position:"absolute",background:"none",border:"1px #ffffff solid",zIndex:9999,display:"none",margin:0,width:w+"px", height:h+"px",left:(($(window).width()-w)/2)+"px",top:(($(window).height()-h)/2)+"px"});
			}
			PreviewBox.$background;
			if(w>800||h>600){
				var c_bg_h = Number(h)+84;
				var c_bg_w = Number(w)+4;
				PreviewBox.$controls_bg.fadeIn(500).animate({width:w+"px", height:c_bg_h+"px",marginLeft:"-"+(w/2)+"px",marginTop:"-"+(c_bg_h/2)+"px",top:"50%",left:"50%"},500);
			}else{
				PreviewBox.$controls_bg.css({top:"50%",left:"50%",display:"block",width:"806px", height:"686px",marginLeft:"-402px",marginTop:"-342px"}).fadeIn(500);
			}
			PreviewBox.$img_background.removeClass().fadeIn(500).focus();
			$image.attr({src:url, width:w, height:h}).appendTo("body").load(function() { $(this).show(); PreviewBox.$img_background.addClass("loaded"); });
			$(document).bind('keydown.pbHandleKeyDown',PreviewBox.HandleKeyDown).bind('click.pbHide',PreviewBox.Hide);
		},
		Hide:function() {
			PreviewBox.$background.hide()
			PreviewBox.$img_background.hide()
			PreviewBox.$controls_bg.hide()
			$("#modal-image").hide().remove()
			$(document).unbind('keydown.pbHandleKeyDown').unbind('click.pbHide');
		},
		Next:function() {
			$("#modal-image").hide().remove();
			var next = PreviewBox.index+1;
			if(next>(PreviewBox.total-1)){ next = 0; }
			PreviewBox.$parent.find("img").eq(next).click();
		},
		Prev:function() {
			$("#modal-image").hide().remove()
			var prev = PreviewBox.index-1;
			if(prev<0){ prev = PreviewBox.total-1; }
			PreviewBox.$parent.find("img").eq(prev).click();
		}
	}
	
	
	
	/*
	if($.browser.msie&&$.browser.version<7) {
		if($("img[title^='pb::']").length>0){
			$("img[title^='pb::']").each(function(){ 
				var newtitle = String($(this).attr('title')).split(";;");
				var largeimg = String(newtitle[0]).substr(4).split(",");
				$(this).attr('title',newtitle[1]);
				$(this).click(function() { var newwin=window.open(largeimg[0],"newwindow"); newwin.focus(); return false; });
			});
		}
	}else{
		
		if($("img[title^='pb::']").length>0){
			PreviewBox.Init();
			$("img[title^='pb::']").each(function(){ 
				var newtitle = String($(this).attr('title')).split(";;");
				var largeimg = String(newtitle[0]).substr(4).split(",");
				$(this).attr('title',newtitle[1]);
				if($(this).parents("div.project").length>0){
					$(this).click(function() { PreviewBox.Show(largeimg[0],newtitle[1],largeimg[1],largeimg[2],$(this),$(this).parent("a")); return false; });
				}else if($(this).parents("div.image_gallery").length>0){
					$(this).click(function() { PreviewBox.Show(largeimg[0],newtitle[1],largeimg[1],largeimg[2],$(this),$(this).parents("div.image_gallery")); return false; });
				}
			});
		}
	}*/
	
	
	
 });