// JavaScript Document

//----ACTIVATING FLASH-----
function flash(flash_content){
	document.write(flash_content);
	}
//----ACTIVATING FLASH-----


//----ADD FAVORITES, PRINT, MAILTO----
//bookmark
function addfav (fav){//alert(location.href);
	netscape="Hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer'){
		window.external.addFavorite(location.href, fav);
	}
	else if (navigator.appName=='Netscape'){
		alert(netscape);
	}
}
function printp (){
	window.print();
}
//----ADD FAVORITES, PRINT, MAILTO----


//----ADD FAVORITES, PRINT, MAILTO----



jQuery(function() {
	
	function mover(e){
		var event = e || window.event;
		var a = event.target || event.srcElement;
		if(a.nodeName != 'A') a = a.parentNode;
		if(a.className != 'act' && a.nodeName == 'A'){
			clearInterval(a.ov);
			a.ov = setInterval(function(){
				setOpacity(a.firstChild, a.alpha)
				a.alpha-=2;
				if(a.alpha < 0){
					a.alpha = 0;
					setOpacity(a.firstChild, 0)
					clearInterval(a.ov);
				}
			},30);
		}
	}
	function mout(e){
		var event = e || window.event;
		var a = event.target || event.srcElement;
		if(a.nodeName != 'A') a = a.parentNode;
		if(a.className != 'act' && a.nodeName == 'A'){
			clearInterval(a.ov);
			a.ov = setInterval(function(){
			setOpacity(a.firstChild, a.alpha)
				a.alpha+=2;
				if(a.alpha > 10){
					a.alpha = 10;
					setOpacity(a.firstChild, 10)
					clearInterval(a.ov);
				}
			},30);
		}
	}
	if($('#video').get(0))
	thisMovie("videoFile").stopMovie = function(){}
	function callStopMovie(){
    if($('#video').get(0))
		thisMovie("videoFile").stopMovie();
	}
	function thisMovie(movieName){
		if(navigator.appName.indexOf("Microsoft") != -1){
			 return window[movieName]
		}else{
			 return document[movieName]
		}
	}
// thumbnails
	var tid = '#th';
	var pid = '#photo';
	$(tid+' A').click(function(){
		$('#video').hide();
		$('#photo').show();
		setOpacity($(tid+' A.act').removeClass("act").get(0).firstChild, 10);
		//$(tid+' A.act').removeClass("act");
		$(this).addClass("act");
		var re = /small_(\w+).jpg/;
		//var str = $(this).children(2).attr("src");
		var str = $(this).find('IMG:last').attr("src");
		var str = str.replace(re, "big_$1.jpg");
		$(pid+' A').attr("href", str );
		$(pid+' A IMG:first-child').attr("src", str );
		callStopMovie();
		return false;
	});
	
	var lArr = $(tid+' A').get().concat($('#gallery A').get()).concat($('div.featured div.gallery A').get());
	for(var i=0; i<lArr.length; i++){
		lArr[i].alpha = 10;
		lArr[i].onmouseover = mover;
		lArr[i].onmouseout = mout;
	}
	
	function setOpacity(obj, value) {
		obj.style.opacity = value/10;
		if(window.showHelp)obj.style.filter = 'alpha(opacity=' + value*10 + ')';
	}

	function stopProp(e){
		var event = e || window.event;
		if(event.stopPropagation){
			event.stopPropagation();
		}else{
			event.cancelBubble = true;  
		}
	}
	
	
// gallery
	var gid = '#gallery';
	var lid = '#btn_l';
	var rid = '#btn_r';
	
	var pact = 0;
	var pimg = $(tid+' IMG.abs:first-child').attr('src');
	$(gid+" div.pages IMG.abs").each(function(i){
		if($(this).attr('src') == pimg){
			pact = -Math.floor(i/7);
		}
	})
	var count = $(gid+" div.page").length;
	if(pact >= 0){$(lid).css('visibility', 'hidden');}else{$(lid).css('visibility', 'visible');}
	if(-(pact) >= count-1){$(rid).css('visibility', 'hidden');}else{$(rid).css('visibility', 'visible');}
	
	//$(lid).css('visibility', 'hidden');
	//if(count == 1)$(rid).css('visibility', 'hidden');
	$(gid+" div.pages").css('width', 100*count+'%');
	$(gid+" div.page").css('width', 100/count+'%');
	$(gid+" div.pages").css('left', 100*pact+'%')
	//$(gid+" div.pages").get(0).style.left = 100*pact+'%';
	$(gid).css('display', 'block');
	
	if($.browser.opera){
		var operax = $(gid).get(0).offsetWidth - $(gid+" div.page:first-child").get(0).offsetWidth;
		$(gid+" div.page").css('marginRight', operax+'px');
		$(gid+" div A:last-child").css('marginRight', -operax+'px');
		//alert($(gid+" div.page:first-child").get(0).offsetWidth)
	}
	
	var gobj = $(gid+" div.pages").get(0);
	//var pact = 0;
	var animate = 0;
	$(rid).click(function(){gmove(-1)});
	$(lid).click(function(){gmove(1)});
	
	function gmove(dir){
		if(!animate){
			if(pact+dir >= 0){$(lid).css('visibility', 'hidden');}else{$(lid).css('visibility', 'visible');}
			if(-(pact+dir) >= count-1){$(rid).css('visibility', 'hidden');}else{$(rid).css('visibility', 'visible');}
			animate=1;
			var t = 0;
			var b = pact*100;
			pact+=dir;
			if(-pact>=count)pact=-(count-1);
			if(-pact<0)pact=0;
			var c = pact*100;
			var d = 800;
			var inc = 40;
			var intt = setInterval(function(){
				if(t < d){
					gobj.style.left = easeInOutElastic(t+=inc,b,c-b,d,1,1)+'%';
				}else{
					clearInterval(intt);
					animate=0;
				}
			}, inc);
		}
	}
	
	easeInOutElastic = function (t, b, c, d, a, p) {
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	};
	
});



/*var ggg =0;
			$(tid+' A').mouseover(function(){ggg=0;
				//$(this).find('IMG:first').fadeOut('fast');
				var par = this;
				var img = this.firstChild.firstChild;;
				if(typeof(par.op) == 'undefined'){par.op=10;}
				clearInterval(par.out)
				par.over = setInterval(function(){
					if(par.op-2 <= 0){
						par.op = 0;
						$(img).css('opacity', par.op/10);
						clearInterval(par.over);
						//window.status = $(par).css('opacity');
					}else{
						par.op-=2;
						$(img).css('opacity', par.op/10);
					}
					$('#gg').html($(img).css('opacity'))
					window.status = ggg++ +'over';
					//if(ggg==100)ggg=0;
				},200);
			});
			$(tid+' A').mouseout(function(){
				//$(this).find('IMG:first').fadeIn('fast');
				var par = this;
				var img = this.firstChild.firstChild;;
				//if(!par.op)par.op=0;
				clearInterval(par.over)
				par.out = setInterval(function(){
					if(par.op-(-2) >= 10){
						par.op = 10;
						$(img).css('opacity', par.op/10);
						clearInterval(par.out);
						//window.status = $(par).css('opacity');
					}else{
						par.op -= -2;
						$(img).css('opacity', par.op/10);
					}
					$('#gg').html($(img).css('opacity'))
					window.status = ggg++ +'out';
					//if(ggg==100)ggg=0;
				},200);
			});*/


