//jQuery.noConflict();

(function($) {
	$.fn.customFadeTo = function(speed, to, callback) {
		$(this).fadeTo(speed, to, function() {
			if($.browser.msie) {
				$(this).get(0).style.removeAttribute('filter');
			}
			if(callback != undefined)
				callback();
		});
	};

	$.fn.ScrollTo = function(speed, callback) {
		var top = jQuery(this).offset().top;
		if ('BODY' == jQuery(this).attr('tagName')) {// for IE6
			top = 0;
		}
		$('html, body').animate({scrollTop: top}, speed, "easeOutExpo", callback);
	};

	$.fn.sustoslideshow = function(covers) {
		var pbox = $(this);
		var imgpos = new Array();
		imgpos[0] = '0';
		imgpos[1] = '-130px';
		imgpos[2] = '-260px';
		//imgpos[3] = '-390px';
		var imgposcount = 0;
		var setimg = null;
		$('<div class="container"></div>').appendTo(pbox).css({
			'margin': '0',
			'padding': '0',
			'background': 'transparent'
		});
		var efxbox = pbox.children('.container');

		function scr() {
			pbox.css({
				'width': '100%',
				'height': '130px',
				'padding': '0'
			});
			efxbox.css({
				'position': 'relative',
				'left': '0',
				'opacity': '0',
				'width': '660px',
				'height': '130px',
				'padding': '0',
				'zIndex':'1',
				'backgroundImage':'url('+covers+')',
				'backgroundPosition': '0 0'
			}).animate({
				'opacity': '1.0'
			},3000,'easeInQuart',function(){
				imgposcount++;
				bgposchange(pbox,imgposcount);
			});
		}
		function bgposchange(obj,pos) {
			clearTimeout(setimg);
			var mpos = imgpos[pos];
			obj.css({
				'backgroundImage':'url('+covers+')',
				'backgroundPosition': '0 '+mpos
			});
			var crosstime = 1000*6;
			setimg = setTimeout(function() { islide('fade'); },crosstime);
		}
		// efx = 'fade', 'slide', 'slidedown'
		function islide(efx) {
			switch (efx) {
				case 'slide':
					efxbox.animate({
						'opacity': '0.5',
						//'width': '1%',
						'left': '100%'
					},800,'easeInQuart',function(){
						bgposchange(efxbox,imgposcount);
						efxbox.css({
							'opacity': '1.0',
							'width': '100%',
							'left': '0'
						});
						if (imgposcount < imgpos.length-1) {
							imgposcount++;
						} else {
							imgposcount = 0;
						}
						bgposchange(pbox,imgposcount);
					});
					break;
				case 'fade':
					efxbox.animate({
						'opacity': '0'
					},800,'easeInQuart',function(){
						bgposchange(efxbox,imgposcount);
						efxbox.css({
							'opacity': '1.0'
						});
						if (imgposcount < imgpos.length-1) {
							imgposcount++;
						} else {
							imgposcount = 0;
						}
						bgposchange(pbox,imgposcount);
					});
					break;
				case 'slidedown':
					efxbox.animate({
						'opacity': '0',
						//'height': '0',
						//'width': '1%',
						//'left': '100%',
						'top': '100%'
					},800,'easeInQuart',function(){
						bgposchange(efxbox,imgposcount);
						efxbox.css({
						'opacity': '1.0',
						'height': '100%',
						'width': '100%',
						'left': '0',
						'top': '0'
						});
						if (imgposcount < imgpos.length-1) {
							imgposcount++;
						} else {
							imgposcount = 0;
						}
						bgposchange(pbox,imgposcount);
					});
					break;
			}
			var crosstime = 1000*5;
			setimg = setTimeout(function() { islide(); },crosstime);
		}

		
		return scr();

	};

})(jQuery);

jQuery(function($){

	var frame = jQuery('#main .contents');
	$('div.mpro').click(function () {
		var id = this.id.substring(1);
		var mid = this.title.substring(6);
		viewdetailn(id,mid);
		return false;
	});
	$('#sidebar ul.prof li a').click(function () {
		var defhref = this.href.split('/');
		var id = defhref[defhref.length -1];
		var mid = this.rel.substring(6);
		viewdetailn(id,mid);
		return false;
	});

	function viewdetailn(id,mid) {
		var detail = 'http://www.voice.sc/profiledetail/'+id;
		var mitems = 'http://www.voice.sc/profileitems/'+mid;
		frame.load(detail);
		$('#memberitems').load(mitems);
	}

	function viewdetail(id) {
		var detail = 'http://www.voice.sc/profiledetail/'+id;
		frame.customFadeTo(400,0,function(){
			frame.css({"opacity":"0.0"});
			frame.load(detail,function(){
				frame.customFadeTo(600,1.0,n())
			});
		});
	}

	function n() {
	}

	$('a.ptop').click(function(){
		jQuery('#top').ScrollTo(800);
		return false;
	});

	$("#gnavi ul.lavaLamp").lavaLamp({
		fx    : "easeOutElastic",
		speed : 500,
		click : function(event, menuItem) {
		}
	});

	SUSTO.machange();

	$('a img').mouseover( function() {
		$(this).css({
			"opacity":"0.7"
		})
		if($.browser.msie) {
			$(this).get(0).style.removeAttribute('filter');
		}
	});
	$('a img').mouseout( function() {
		$(this).css({
			"opacity":"1.0"
		})
		if($.browser.msie) {
			$(this).get(0).style.removeAttribute('filter');
		}
	});

	$('ul.snavi li a').mouseover( function() {
		$('li.back').css({
			"opacity":"0"
		})
		if($.browser.msie) {
			$(this).get(0).style.removeAttribute('filter');
		}
	});
	$('ul.snavi li a').mouseout( function() {
		$('li.back').css({
			"opacity":"1.0"
		})
		if($.browser.msie) {
			$(this).get(0).style.removeAttribute('filter');
		}
	});

	var coverimg = new Image();
	coverimg.src = 'http://www.voice.sc/common/voice02/style/images/covers.jpg';
	var covers = coverimg.src;
	if ($('#cover').length) {
		$('#cover').sustoslideshow(covers);
	}
	$('a.thickbox').fancybox({
		'overlayShow'			: true,
		'overlayOpacity'		: 0,
		'imageScale': true,
		'zoomOpacity'			: true,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'frameWidth'			: 400,
		'frameHeight'			: 380,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack',
		'hideOnContentClick': false
	});

});

if (!SUSTO) var SUSTO={};

SUSTO.machange = function () {
	var mad = document.getElementById("mad");
	var refobj = mad.firstChild.nodeValue;
	var dot = new RegExp("\-dot\-","g");
	refobj = refobj.replace("\-atmark\-","@").replace(dot,".");
	mad.replaceChild(document.createTextNode(refobj),mad.firstChild);
	mad.href = "mailto:"+refobj;
}