// i in object: iin(object);
function iin(obj) {
	var msg;
	for(var i in obj){
		msg += '[ '+i+' ] = '+' '+obj[i]+'\n';
	}
	return msg;
}
//----ADD FLASH FAVORITES, PRINT, MAILTO----
function flash(flash_content){
	document.write(flash_content);
	}
//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();
}
function $$(id){return document.getElementById(id);}
//----ADD FAVORITES, PRINT, MAILTO----


	var lastdt=null;
	var not;
	function fsh(obj){
		if(not){not=0; return}
		//
		var next = obj.nextSibling.nodeType == 1 ? obj.nextSibling : obj.nextSibling.nextSibling;
		if(next.offsetHeight){
			obj.className = '';
			next.style.display = 'none';
		}else{
			obj.className = 'open';
			next.style.display = 'block';
			if(!lastdt)lastdt = obj.parentNode.getElementsByTagName('DT')[0];
			if(lastdt != obj){
				lastdt.className = '';
				var next2 = lastdt.nextSibling.nodeType == 1 ? lastdt.nextSibling : lastdt.nextSibling.nextSibling;
				next2.style.display = 'none';
			}
			lastdt = obj;
		}
	}
	function fshimg(obj){
		if(!obj.parentNode.run){
			obj.parentNode.run = 1;
			obj.parentNode.parentNode.ibig = obj.parentNode.parentNode.getElementsByTagName('IMG');
			obj.parentNode.parentNode.last = obj.parentNode.parentNode.ibig[0];
			var imgarr = obj.parentNode.getElementsByTagName('IMG');
			for(var i=0; i<imgarr.length; i++){
				imgarr[i].num = i;
			}
		}
		obj.parentNode.parentNode.last.style.display = 'none';
		obj.parentNode.parentNode.ibig[obj.num].style.display = 'block';
		obj.parentNode.parentNode.last = obj.parentNode.parentNode.ibig[obj.num];
	}


//////////

jQuery(function() {
	var $ = jQuery;
	
	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 = /(\w+)_s.jpg/;
		//var str = $(this).children(2).attr("src");
		var str = $(this).find('IMG:last').attr("src");
		var str = str.replace(re, "$1_b.jpg");
		$(pid+' A').attr("href", str );
		$(pid+' A IMG:first-child').attr("src", str );
		callStopMovie();
		return false;
	});

	var lArr = $(tid+' A').get().concat($('#igallery A').get()).concat($('div.featured div.igallery 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 = '#igallery';
	var lid = '#btn_l';
	var rid = '#btn_r';
	var aid = '#btn_arr';
	makeGallery(gid,lid,rid);

	var gid = '#igallery2';
	var lid = '#btn_l2';
	var rid = '#btn_r2';
	var aid = '#btn_arr2';
	makeGallery(gid,lid,rid);

	function makeGallery(gid,lid,rid){
		var pact = 0;
		var animate = 0;
		var count,gobj;
		if($(gid).get(0))
		$(gid).get(0).act = pact;   ///////////
		
		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/8);
			}
		})
		
		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:nth-child(8)").css('marginRight', -operax+'px');
			$(gid+" div A:last-child").css('marginRight', -operax+'px');
			//alert($(gid+" div.page:first-child").get(0).offsetWidth)
		}
		
		
		/*$(aid+" img").each(function(i){ 
      for(i=0;i<this.length;i++){ 
        this[i].ix = i; 
        this[i].btnid = aid; 
        //this[i].onclick=function(){ gscroll(this.btnid, this.ix);}
       }
    })*/
    $(aid+" img").each(function(i){  this.ix = i; this.btnid = aid; })
		//$(aid+" img").click(function(){ gscroll(this.ix); })
		//$(aid+" img").each(function(i){ alert(i); })
		$(aid+" img").click(function(){ gscroll(this.btnid, this.ix); })
		
		function gscroll(btnid,id){   ///////////////
			if(!animate){
        //alert(iin($(btnid+" img").get))
				//alert($(btnid+" img").get(id).nodeName)
				$(btnid+" img").get(id).src='img/design/fp_1.gif';
				$(btnid+" img").get(-pact).src='img/design/fp_0.gif';
				gmove(-pact-id);
			}
		}

		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;
			$(gid).get(0).act = pact; //////////
			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;
	};

});








