// Funcion window onload con JQuery
$(window).load(function(){  
preCarga('images/loading.gif');
Nifty("div.box0","big");
Nifty("div.box1","big");
Nifty("div.box2","big");
Nifty("div.box3","big");
Nifty("div.box4","big");
Nifty("div.box5","big");
Nifty("div.box6","big");
Nifty("div.box7","big");
Nifty("ul.postnav a","transparent");
Nifty("ul.postnav2 a","transparent");
Nifty("ul.categoria h3","top");
Nifty("ul.categoria div","bottom same-height");
Nifty("ul.table_right h3","top");
Nifty("ul.table_right div","none same-height"); 
});  

// Precarga de loading.gif
function preCarga() {
if (!document.images) return;
var ar = new Array();
var arguments = preCarga.arguments;
for (var i = 0; i < arguments.length; i++) {
ar[i] = new Image();
ar[i].src = arguments[i];
}
}

// Muestra loading.gif
function CargaLoading() {
$('#loading').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
}

//Texto por defecto en el campo de busqueda
$(document).ready(function()
{
$("#search").focus(function(srcc)
{
if ($(this).val() == $(this)[0].title)
{
$(this).removeClass("defaultTextActive");
$(this).val("");
}
});
$("#search").blur(function()
{
if ($(this).val() == "")
{
$(this).addClass("defaultTextActive");
$(this).val($(this)[0].title);
}
}); 
$("#search").blur();       
});

// Search form
$(document).ready(function() {
$("#search_form").validate({
errorElement: "search",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loadingsearch) {
$('#loadingsearch').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
search_form.submit();
}
});
});

// Resend
$(document).ready(function() {
$("#form_resend").validate({
errorElement: "resend",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingresend').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
form_resend.submit();
}
});
});

// Aligera
$(document).ready(function() {
$("#form_aligera").validate({
errorElement: "aligera",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingresize').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
form_aligera.submit();
}
});
});

// Contacto
$(document).ready(function() {
$("#form_contact").validate({
errorElement: "contact",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingcontact').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
form_contact.submit();
}
});
});

// Login
$(document).ready(function() {
$("#form_login").validate({
errorElement: "login",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadinglogin').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
form_login.submit();
}
});
});

// Forgot
$(document).ready(function() {
$("#form_forgot").validate({
errorElement: "forgot",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingforgot').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
form_forgot.submit();
}
});
});

// Signup
$(document).ready(function() {
$("#form_signup").validate({
errorElement: "signup",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingsignup').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
form_signup.submit();
}
});
});

// Selectcity
$(document).ready(function() {
$("#frmCitys").validate({
errorElement: "citys",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingcitys').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
frmCitys.submit();
}
});
});

// Selectcat
$(document).ready(function() {
$("#frmCats").validate({
errorElement: "cats",
errorPlacement: function(error, element) {
error.appendTo( element.parent("div").next("span"));
},
submitHandler: function(loading) {
$('#loadingcats').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
frmCats.submit();
}
});
});

// Post
$(document).ready(function() {
$("#frmPost").validate({
errorElement: "div",
errorContainer: $("#errores"),
errorPlacement: function(error, element) {
error.appendTo( element.parent("span").next("span"));
},
success: function(label) {
label.text("ok!").addClass("success");
},	
rules: {	
currency: {
required: function(element) {
return $("#price").val() != '';
}}
},
submitHandler: function(loading) {
$('#loadingpost').html('<img style="vertical-align: middle; margin-bottom:2px" src="images/loading.gif" width="16" height="16" border="0" alt="Submit...">');
frmPost.submit();
}
});
});
