$(function() {
var tabs = [],
ind = 0,
inter, 
time = 10000;

$.jQueryRandom = 0;
$.extend($.expr[":"],
{
random: function(a, i, m, r) {
	if (i == 0) {
		$.jQueryRandom = Math.floor(Math.random() * r.length);
	};
	return i == $.jQueryRandom;
}
});

setInterval(function(){
	$('.catHead:random').fadeIn(3000).delay(1000).fadeOut(3000);
}, 2000)

function change(string) {
	
$('.tab:not(#'+string+')').hide();
if ($.browser.msie && $.browser.version.substr(0, 3) == '6.0'){
	$('.tab#'+string).show();	
}else{
	$('.tab#'+string).fadeIn();	
}

$('.htabs a:not(#'+string+'t)').parent().removeClass('bgChange');
$('.htabs a[href=#'+string+']').parent().addClass('bgChange');
}

function next() {
	change(tabs[ind++]);
	if(ind >= tabs.length){
	ind=0;	
	}
}

$('.tab').map(function(){
  tabs[ind++] = $(this).attr('id');
})
ind = 1;
$('.tab:not(:first)').hide();
$('.tab:first').show();
$('#'+tabs[0]+'t').addClass('select');

$('.htabs a').click(function() {
  clearInterval(inter);
  string = $(this).attr('href').split('#')[1];
  change(string);
  return false;
  });

inter = setInterval(next, time)


$('#slideCont').hover(function(){
  clearInterval(inter)
		   },function() {
			 inter = setInterval(next, time);
  });
					  
$('.videosName, .videosImg, .videosLink, .homepage_videosImg').click(function(){
	$('.overlay-video').show();
	if($(this).hasClass('homepage_videosImg')){
		id = $(this).attr('id');
	}else{
		id = $(this).parents('.videosRow').attr('id');
	}
	$('#videoContainer').html('<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/'+id+'?rel=0" frameborder="0" allowfullscreen></iframe>');
})

$('.checkLogin').click(function(e){
	e.preventDefault();
	href = $(this).attr('href');
	$.ajax({
		url : 'ajax/checkLogin.php',
		type : 'POST',
		data : 'check=1',
		success : function(d){
			if(d == 1){
				window.location = 'http://'+href;
			}else{
				e.preventDefault();
				$('.overlay').show();
			}
		}
					
	})
})


$('.leftMenu').mouseover(function(){
	if(!$(this).hasClass('menuSelected')){
	$(this).css({'background':'#4A354A'})
	}
}).mouseout(function(){
	if(!$(this).hasClass('menuSelected')){
	$(this).css({'background':'none'})
}
})




$('#prevImg').live('click', function(){
	img = $('.thumbs').find('.selected');
	previous = img.prev();
	if(previous.size() == 0){
		return false;
	}
	/*
	if(previous.height() > 1000){
		previous.find('#bottomOverlay').css({'bottom':'650px'})
	}*/
	img.removeClass('selected').addClass('hideImg');
	previous.addClass('selected');
})

/*
if($('.thumbs').find('#bottomOverlay').height() > 1000){
	$('.thumbs').find('#bottomOverlay').css({'bottom':'650px'})
}*/

$('#nextImg').live('click',function(){
	img = $('.thumbs').find('.selected');
	next = img.next();
	if(next.size() == 0){
		return false;
	}/*
	if(next.height() > 1000){
		next.find('#bottomOverlay').css({'bottom':'650px'})
	}*/
	img.removeClass('selected').addClass('hideImg');
	imgUrl = next.find('img').attr('src');
	next.addClass('selected');
})

$('.tagLabels').live('mouseover', function(){
	$this = $(this);
	name = $this.text();
	$(".tag:contains("+name+")").show();
}).mouseout(function(){
	$this = $(this);
	name = $this.text();
	$(".tag:contains("+name+")").hide();
})


$(".likePhoto").live('click',function(){

	$this = $(this);
	photo = $this.attr('name');
	name = $this.attr('id');
	loc = $this.attr('rel');
	aid = $this.attr('lang');
	dataString = 'location='+loc+'&photo='+photo+'&name='+name+'&aid='+aid;  
	$.ajax({
		type: 'POST',
		data: dataString,
		url: 'ajax/likePhoto.php',
		success: function(data){
		  $this.find(".likePhotoText").text('The picture has been added');
		}
	})
	
}) 


$('.likeLoader').ajaxStart(function(){
	$(this).show();
}).ajaxStop(function(){
	$(this).hide();
})
	
	
$('.pageHead a').mouseover(function(){
	$(this).css({'text-decoration':'underline'});
}).mouseout(function(){
	$(this).css({'text-decoration':'none'});
})
	
	
	
$('[name=submitRegisterUser]').click(function(){
	if($('[name=firstName]').val() == ''){
		$('#login-mainError').html('Please enter your first name');
		return false;
	}
	if($('[name=lastName]').val() == ''){
		$('#login-mainError').html('Please enter your last name');
		return false;
	}
	if($('#registerEmail').val() == ''){
		$('#login-mainError').html('Please enter your email');
		return false;
	}
	if(!(validateEmail($('#registerEmail').val()))){
		$('#login-mainError').html('Invalid email');
		return false;
	}
	if($('#registerPassword').val() == ''){
		$('#login-mainError').html('Please enter a password');
		return false;
	}
	if($('[name=password2]').val() == ''){
		$('#login-mainError').html('Please confirm your password');
		return false;
	}
	if($('#registerPassword').val() != $('[name=password2]').val()){
		$('#login-mainError').html('Your passwords do not match');
		return false;
	}
})	
	
	
	
	
});



//VALIDATION FUNCTIONS 

	//numbers spaces + ()
	function validatePhone(data) { 
			var valPhone = /^[\d\s+()-]+$/m;
			if (valPhone.test(data)) {
					return true;
				}else{
					return false;
				}
	} 
	
	function validateEmail(data) {
			var valEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (valEmail.test(data)) {
					return true;
				}else{
					return false;
				}
	}
	
	//letters numbers over 1 below 15
	function validatePass(data) {
			var valPass = /^[\d\s\w()-]{2,15}$/m;
			if (valPass.test(data)) {
				return true;
			}else{
				return false;
			}
	}
	
	//letters numbers over 1 below 15
	function validateNames(data) {
			var valName = /^[\d\s\w()-]{2,15}$/m;
			if (valName.test(data)) {
				return true;
			}else{
				return false;
			}	
	}
	
	//letters numbers () - over 2 below 20
	function validateSearch(data) {
			var valReq = /^[\d\s\w()-//'//"\!]{2,15}$/m;
			if (valReq.test(data)) {
				return data;
			}else{
				return false;
			}				
	}


