$(document).ready(function() {	

$('.homePics').cycle();
$('.retouchMain').cycle();

$('#header #nav a').mouseover(function() {
	var thisPage = $(this).attr('title');
	
		if (thisPage ==  'home') {
			$('img#brush').css('left', '350px').css('visibility', 'visible');
		}
		if (thisPage ==  'artist') {
			$('img#brush').css('left', '400px').css('visibility', 'visible');
		}
		if (thisPage ==  'folio') {
			$('img#brush').css('left', '510px').css('visibility', 'visible');
		}
		if (thisPage ==  'retouch') {
			$('img#brush').css('left', '610px').css('visibility', 'visible');
		}
		if (thisPage ==  'news') {
			$('img#brush').css('left', '770px').css('visibility', 'visible');
		}
		if (thisPage ==  'contact') {
			$('img#brush').css('left', '830px').css('visibility', 'visible');
		}	
});

$('#header #nav a').mouseout(function() {
	var thisPage = $('body').attr('id');
	initBrush(thisPage);
});
 
$ (".galleryCarousel").jMyCarousel ({  
        visible: '100%',  
		speed: 1500,
        eltByElt: true ,
    });  


$("#mailFrm").submit(function() {
	dataString = $("#mailFrm").serialize(); 
	$.ajax({
		type: "POST", 
		url: "forms_cb.php",
		data: dataString,
		dataType: "json",
		success: function(data) {
    	 if (data.success == 'FAIL')
				{
					$("#statusbox").modal();
					$("#statusbox").html('<p>' + data.message + '</p><ul></ul>');
					$("#statusbox" + ' ul').empty().addClass('mailErrors');
					$.each(data.errors, function(index, value) {
					$("#statusbox" + ' ul').append("<li>" + value.replace('_', ' ') + "</li>");
					});
				} 
				else  if (data.success == 'PASS') 
				{
					$("#statusbox").modal();
					$("#statusbox").html('<ul></ul>');
					$("#statusbox" + ' ul').empty().addClass('mailSuccess');
					$.each(data.pass, function(index, value) {
					$("#statusbox" + ' ul').append("<li>" + value.replace('_', ' ') + "</li>");
					});
					resetForm('mailFrm');
				}								
			}
	});
	return false; 
	});

$(".galleryCarousel ul li").click(function() {
	dataString =  "action=getImage&id="+ $(this).attr('id').replace('img_', '');

	$.ajax({
		type: "POST", 
		url: "forms_cb.php",
		data: dataString,
		dataType: "json",
		success: function(data) {
			$(".imageInfo").html("&quot;" + data['title'] + "&quot;<br />" + data['details']);
			
				if (data['sold_status'] != 1){
					$(".imageInfo").append("<br /><b>$" + addCommas(data['price']) + "</b>");
				}
				
    		$(".imageMain").html("<img src='./folio/large/" + data['image'] + "' />");					
		}
	});
	return false; 
});

$(".retouchLinks a").mouseover(function(){
	$(this).stop().css('background-position','0px -90px').animate({width:'150px', height:'153px'}, { duration:400, easing: 'easeOutBounce'});
 
	var thisID = $(this).attr('id');
	
	$(".retouchMain").html("<img src='images/retouch/" + thisID + "_a.jpg' width='350' height='498' alt='image_a' /><img src='images/retouch/" + thisID + "_b.jpg' width='350' height='498' alt='image_b' />");
	
	$('.retouchMain').cycle({
		timeout: 1000,
		delay:0,
		speed:400
	});
	
	return false; 
});

$(".retouchLinks a").mouseout(function(){
	$(this).stop().css('background-position','-30px 0px').animate({width:'95px', height:'89px'}, { duration:0, easing: 'easeOutBounce'});
	 
	$(".retouchMain").html("<img src='images/retouch/rtOne_a.jpg' width='350' height='498' alt='image_a' /><img src='images/retouch/rtOne_b.jpg' width='350' height='498' alt='image_b' /><img src='images/retouch/rtTwo_a.jpg' width='350' height='498' alt='image_a' /><img src='images/retouch/rtTwo_b.jpg' width='350' height='498' alt='image_b' /><img src='images/retouch/rtThree_a.jpg' width='350' height='498' alt='image_a' /><img src='images/retouch/rtThree_b.jpg' width='350' height='498' alt='image_b' /><img src='images/retouch/rtFour_a.jpg' width='350' height='498' alt='image_a' /><img src='images/retouch/rtFour_b.jpg' width='350' height='498' alt='image_b' />");
	
	$('.retouchMain').cycle({
		delay:500,
		speed:500
	});
	
	return false; 
});
	          	 
});


function initBrush()
{
	var thisPage = $('body').attr('id');
	
	if (thisPage == 'homePg') {
		$('img#brush').css('left', '350px').css('visibility', 'visible');
	}
	if (thisPage == 'artistPg') {
		$('img#brush').css('left', '400px').css('visibility', 'visible');
	}
	if (thisPage ==  "folioPg") {
		$('img#brush').css('left', '510px').css('visibility', 'visible');
	}
	if (thisPage ==  'retouchPg') {
		$('img#brush').css('left', '610px').css('visibility', 'visible');
	}
	if (thisPage ==  'newsPg') {
		$('img#brush').css('left', '770px').css('visibility', 'visible');
	}
	if (thisPage ==  'contactPg') {
		$('img#brush').css('left', '830px').css('visibility', 'visible');
	}	
}


function initGallery()
{
	$(".galleryCarousel li").siblings(':first-child').trigger("click");
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

// FORM RESET - CLEARS FORM OF PREVIOUSLY ENTERED DATA
function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}
