
var active_tab_profile = false;
var active_tab_interaction = false;
var myFx;

var sendToFriend;
var sendToBusiness;
var formCheck;


window.addEvent('domready', function(){

	if ($('form_judge')) {
		formCheck = new FormCheck('form_judge', {
			display : {
				keepFocusOnError: 1,
				scrollToFirst : false
			},
			submitByAjax : true,
			onAjaxRequest: function() {
				//
			},
			onAjaxSuccess: function(str) {
				doAjaxSuccess(str);
			}
		});
		/*
		 * Dispose fields under create new user
		 */
		formCheck.dispose($('create_name_first'));
		formCheck.dispose($('create_name_last'));
		formCheck.dispose($('create_sex_m'));
		formCheck.dispose($('create_sex_f'));
		formCheck.dispose($('create_birthyear'));
		formCheck.dispose($('create_zip'));
		formCheck.dispose($('create_checkemail'));
		formCheck.dispose($('create_checkemailconfirm'));
		formCheck.dispose($('create_checkemailconfirm'));
		formCheck.dispose($('create_password'));
	}
	
	if ($('form_write')) {
		formCheck = new FormCheck('form_write', {
			display : {
				keepFocusOnError: 1,
				scrollToFirst : false
			},
			submitByAjax : true,
			onAjaxRequest: function() {
				//
			},
			onAjaxSuccess: function(str) {
				doAjaxSuccess(str);
			}
		});
		/*
		 * Dispose fields under create new user
		 */
		formCheck.dispose($('create_name_first'));
		formCheck.dispose($('create_name_last'));
		formCheck.dispose($('create_sex_m'));
		formCheck.dispose($('create_sex_f'));
		formCheck.dispose($('create_birthyear'));
		formCheck.dispose($('create_zip'));
		formCheck.dispose($('create_checkemail'));
		formCheck.dispose($('create_checkemailconfirm'));
		formCheck.dispose($('create_checkemailconfirm'));
		formCheck.dispose($('create_password'));
	}
	
	
	if ($('send_to_friend')) {
		formCheck = new FormCheck('send_to_friend', {
			display : {
				scrollToFirst : true
			}
		});
	}


	// The stars in the judge box
		var stars = $$('.biz-judge-stars .image');
		stars.each(function(star, index) {
			star.addEvent('mouseover', function(e){
				// Reset stars
				stars.each(function(i, j) {
					if (j<=index) {
						i.addClass('on');	
					} else {
						i.removeClass('on');
					}
				});
			});
			star.addEvent('mouseout', function(e){
				set = $('form_judge').stars.value-1;
				stars.each(function(i, j) {
					if (j<=set) {
						i.addClass('on');	
					} else {
						i.removeClass('on');
					}
				});	
			});
			star.addEvent('click', function(e){
				$('judge-more').style.display = 'block';
				$('form_judge').stars.value = index+1;
				$$('.comment-help').each(function(block, block_index) {
					block.style.display = (block_index == index) ? 'block' : 'none';
				});
			});
		});


	// The pricestars in the judge box
		var pricestars = $$('.biz-judge-pricestars .image');
		pricestars.each(function(pricestar, index) {
			pricestar.addEvent('mouseover', function(e){
				// Reset stars
				pricestars.each(function(i, j) {
					if (j<=index) {
						i.addClass('on');	
					} else {
						i.removeClass('on');
					}
				});
			});
			pricestar.addEvent('mouseout', function(e){
				set = $('form_judge').pricestars.value-1;
				pricestars.each(function(i, j) {
					if (j<=set) {
						i.addClass('on');	
					} else {
						i.removeClass('on');
					}
				});
			});
			pricestar.addEvent('click', function(e){
				$('form_judge').pricestars.value = index+1;
			});
		});

		
	/* ajax replace element text */
	if($$('.ajax-replace')) {
		$$('.ajax-replace').each(function(ajax, index) {
			ajax.addEvent('click', function(event) {
				//prevent the page from changing
				event.stop();
				//make the ajax call, replace text
				var req = new Request.HTML({
					method: 'get',
					url: ajax.get('href'),
					data: { 'do' : '1' },
					onRequest: function() {
						//
					},
					update: ajax.get('rel'),
					onComplete: function(response) {
						//
					}
				}).send();
			});
		});
	}

});


function thumb_rating(id,flag) {
	alert(flag + "-" + script_root);

}


function playVideo(obj) {
	if (obj != false) {
		$('video').set('html', '<object width="288" height="233"><param name="movie" value="http://www.youtube.com/v/'+obj+'&hl=en&fs=1&autoplay=1"></param><param name="allowFullScreen" value="true"><param name="autoplay" value="1"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+obj+'&hl=en&fs=1&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" autoplay="1" width="288" height="233"></embed></object>');
	} else {
		$('video').set('html', '');
	}
}


function showPopWindow(obj, id, x, y) {

	$$('.pop-window').each(function(item, index) {
		item.setStyle('display', 'none');
	});
	
	var elem = $(id);
	
	elem.setStyle('display', 'block');
	elem.setStyle('left', x);
	elem.setStyle('top', y);
}


function closePopWindow(id) {
	var elem = $(id);
	elem.setStyle('display', 'none');
}


var slideShow = new Class({
	initialize: function(){
		
		$('slideshow').setStyle('display', 'block');

		this.next = 1;
		this.prev = 0;
		this.zIndex = 1;
		
		this.images = $('slideshow').getChildren();
		this.thumbs = $$('.gallery-item');

		this.images.each(function(item, index) {
			if (index!=0) {
				item.setStyle('opacity',0);
			}
		});
		this.size = this.images.length;
		this.nextSlide.periodical(6000, this);
	},

	nextSlide : function() {

		if (this.next>=this.size) {
			this.next = 0;
		}

		element = this.images[this.next];
		element.setStyle('z-index',this.zIndex);
		element.set('tween', {duration: 5000});
		element.tween('opacity', 100);
		
		element2 = this.images[this.prev];
		element2.set('tween', {duration: 2000});
		element2.tween('opacity', 0);

		this.prev = this.next;
		this.next++;
		this.zIndex++;
	}
});