$(
	"#content_left > :first-child,#location > :first-child," +
	"#breeds ul li > :first-child,#eukanuba_top > :first-child," +
	"#eukanuba_bottom > :first-child,#shortcuts > :first-child"
).before( '<div class="bg"></div>' );

$( "#content > h2" ).attr( "id", "content-title" ).append( "<span></span>" );
$( "#content > p:first" ).attr( "id", "content-description" ).html( '<span></span><span class="text">' + $( "#content > p:first" ).html() + "</span>" );
$( "#breeds li h3" ).before( '<div class="img"></div>' );
$( "[class=gallery] li a" ).attr( "rel", "shadowbox[gallery]" );
$( ".gallery.yt li a" ).attr( "rel", "shadowbox[gallery];height=480;width=640" );
$( "[id^=eukanuba] a,#shortcuts a[class!=home]" ).addClass( "popup" );

$( "#panel" ).attr( "id", "_panel" ).attr( "id", "panel" );

$( "a.popup" ).click( function() {
	window.open( $( this ).attr( "href" ) );
	return false;
} );


$( "#shortcuts" ).hover( function() {
	$( this ).children( ".bg" ).addClass( "hover" );
}, function() {
	$( this ).children( ".bg" ).removeClass( "hover" );
} );


// Contact Form

$( "#contactus_container form" ).attr( "onsubmit", "javascript:onContactFormSubmitHandler(); return false;" );
$( "#contactus_container address" ).html( '<span></span><span class="text">' + $( "#contactus_container address" ).html() + "</span>" );

var contactFormHTML = '<div id="contactus_container" style="display: block;">' + $( "#contactus_container" ).html() + "</div>";

$( "#contactus_container" ).remove();

$( "#contactus" ).click( function() {
	
	Shadowbox.open( {
		content	: contactFormHTML,
		height	: 360,
		player	: "html",
		width		: 410
	} );
	
} );

function onContactFormSubmitHandler() {
	
	$( "#contactus_container form" ).disable();
	
	if( !contactFormValidate() ) {
		$( "#contactus_container form" ).enable();		
		return false;
	}
	
	$.ajax( {
		url			: "contact-us/",
		type		: "POST",
		data		: {
			name		: $( "#name" ).val(),
			phone		: $( "#phone" ).val(),
			email		: $( "#email" ).val(),
			knowus	: $( "#knowus" ).val(),
			comment	: $( "#comment" ).val()
		},
		success		: function( r ) {
			
			try {
				
				var data = eval( "(" + r + ")" );
				
				if( data.status == "0" ) {
					alert( data.message );
				} else {
					alert( "Gracias por contactarte con nosotros, responderemos a la brevedad." );
					Shadowbox.close();
					return false;
				}
				
			} catch( e ) {
				
			}
			
			$( "#contactus_container form" ).enable();
			
		},
		complete	: function() {
			$( "#contactus_container form" ).enable();
		},
		error			: function() {
			alert( "No se pudo enviar el mensaje, vuelva a intentar" );
		}
		
	} )
	
}

function contactFormValidate() {
	
	if( $( "#name" ).val() == "" ) {
		alert( "Por favor, ingrese su nombre" );
		$( "#name" ).focus();
		return false;
	}
	
	if( !isValidEmail( $( "#email" ).val() ) ) {
		alert( "Por favor, ingrese su email" );
		$( "#email" ).focus();
		return false;
	}
	
	if( $( "#comment" ).val() == "" ) {
		alert( "Por favor, ingrese su comentario" );
		$( "#comment" ).focus();
		return false;
	}
	
	return true;
	
}



if( $( ".info" ).length == 0 || $( ".yt" ).length == 1 ) {
	Shadowbox.init();
} else {
	
	$( ".info a" )
		.attr( "rel", "shadowbox[Mixed]" )
		.click( function() {
		
		var elem	= $( this );
		var elemParent = elem.parent();
		
		var img		= elem.children( "img" ).attr( "src" ).replace( ".th", "" );
		var name	= elemParent.children( "h3" ).html();
		var breed	= elemParent.children( "h2" ).html();
		var desc	= elemParent.children( "p" ).html();

	  var html = '<div class="container">' +
	    '<div class="img">' +
	  		"<span></span>" +
	      '<img src="' + img + '" alt="' + name + " (" + breed + ')" width="300" />' +
	    "</div>" +
	    '<div class="content">' +
	    	"<h3>" + name + "</h3>" +
	    	"<h2>" + breed + "</h2>" +
	    	"<p>" + desc + "</p>" +
	    "</div>" +
	  "</div>";
	  
	  Shadowbox.open( {
      content	: html,
      player	: "html",
      title		: "<b>" + name + "</b> (" + breed + ")",
      height	: 520,
      width		: 720
	  } );
	  
	  return false;
		
	} );
	
	Shadowbox.init( { skipSetup: true } );

}