//jQuery
//$(function () {
//    if ($.browser.safari) {
//	alert("Loaded");
//    }
//});


$(document).ready(function(){

	$('.sub_nav').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.jpg', '-over.jpg');
	$(this).attr('src', temp);
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.jpg', '.jpg');
	$(this).attr('src', temp);
	});
	
	$(".home_feature").hover(function(){
	$(this).fadeTo("slow", 0);
}, function() {
	$(this).fadeTo("slow", 1);
});
	
	
	$(".sub_nav_item").hover(function(){
	var qindex = $(".sub_nav_item").index(this);
	$(".sub_nav_flag:eq(" + qindex + ")").show();	
	},
	function() {
	if ($(this).parent().hasClass("sub_nav_div")) {	
	var qindex = $(".sub_nav_item").index(this);
	$(".sub_nav_flag:eq(" + qindex + ")").hide();	
	}
	});
	
	
	$('.prod_nav').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.gif', '-over.gif');
	$(this).attr('src', temp);
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.gif', '.gif');
	$(this).attr('src', temp);
	});
	
/* Tabs */	
	var tab_on=0;	
$('.item_tab').click(function() {
var index=$('.item_tab').index(this);
tab_on=index;
for (var i=0; i<$('.item_tab').length ;i++) {
var t=$('.item_tab:eq(' + i + ')').attr('src');
if (i==index) {
t=t.replace('_down.gif', '_up.gif');
$('.item_tab:eq(' + i + ')').attr('src', t);
$('.tab_container:eq(' + i + ')').fadeIn(300);
} else {
t=t.replace('_up.gif', '_down.gif');
$('.item_tab:eq(' + i + ')').attr('src', t);
$('.tab_container:eq(' + i + ')').hide();
}
}
return false;
});

var tab_org;
$('.item_tab').hover(function(){
var temp=$(this).attr('src');
tab_org=temp;
temp=temp.replace('_down.gif', '_up.gif');
$(this).attr('src', temp);
}, 
function() {
if ($('.item_tab').index(this)!=tab_on) {
$(this).attr('src', tab_org);		
}
});
/* Tabs */		
	
	
	$('#map_home').hover(function(){
	var temp=$(this).attr('src')
	temp=temp.replace('.gif', '-over.gif');
	$(this).attr('src', temp);
	}, 
	function() {
	var temp=$(this).attr('src')
	temp=temp.replace('-over.gif', '.gif');
	$(this).attr('src', temp);
	});
	
//$("#find_rep_button").click(function(){
//	$("#rep_detail").slideToggle();									 
//});

$("input#zip").click(function(){
	$("input#zip").val("");				  
});



//$("#rep_search").click(function(){
$("#rep_search_form").submit(function(){
if ($("#rep_detail").css("display")=="none") {

									  
var zip=$("input#zip").val();
if (zip!="") {
var dataString = 'zip=' + zip;
//alert (dataString);

$.ajax({
type: "GET",
url: "/findarep/rep_data.aspx",
data: dataString,
dataType: "xml",
success: function(xml) {
var return_text
$(xml).find('rep_detail').each(function(){
return_text = '<table><tr><td> </td><td bgcolor="#e1dbd3"><div class="rep_citystate">' + $(this).attr('city') + ', ' + $(this).attr('state') + '</div></td></tr>';
//return_text = return_text + $(this).attr('role') + '<br />';
return_text = return_text + '<tr><td><div class="rep_finder_image" style="padding-bottom: 5px;">';
if ($(this).attr('image') != '') { 	return_text = return_text + '<img src="/images/reps/' + $(this).attr('image') + '" />';	}
return_text = return_text + '</div></td><td bgcolor="#e1dbd3"><div class="rep_data">';
return_text = return_text + '<b>' + $(this).attr('name') + '</b><br />';
if ($(this).attr('phone') != '') { 	return_text = return_text + 'Phone: ' + $(this).attr('phone') + '<br />';	}
if ($(this).attr('cell') != '') { return_text = return_text + 'Cell: ' + $(this).attr('cell') + '<br />'; }
if ($(this).attr('fax') != '') { return_text = return_text + 'Fax: ' + $(this).attr('fax') + '<br />'; }
if ($(this).attr('email') != '') { return_text = return_text + '' + $(this).attr('email') + '<br />'; }
return_text = return_text + '</div></td></tr>';
// var name_text = $(this).find('name').text() this would find any nested tags
}); //close each(
$(xml).find('spec_rep_detail').each(function(){
if ($(this).attr('name') != '') {
//return_text = return_text + '<br />' + $(this).attr('role') + '<br />';
return_text = return_text + '<tr><td><div class="rep_finder_image">';
if ($(this).attr('image') != '') { 	return_text = return_text + '<img src="/images/reps/' + $(this).attr('image') + '" />';	}
return_text = return_text + '</div></td><td bgcolor="#e1dbd3"><div class="rep_data">';
return_text = return_text + '<div>Specifier Representative</div>';
return_text = return_text + '<b>' + $(this).attr('name') + '</b><br />';
if ($(this).attr('phone') != '') { 	return_text = return_text + 'Phone: ' + $(this).attr('phone') + '<br />';	}
if ($(this).attr('cell') != '') { return_text = return_text + 'Cell: ' + $(this).attr('cell') + '<br />'; }
if ($(this).attr('fax') != '') { return_text = return_text + 'Fax: ' + $(this).attr('fax') + '<br />'; }
if ($(this).attr('email') != '') { return_text = return_text + '' + $(this).attr('email') + '<br />'; }
return_text = return_text + '</div></td></tr>';
}																						 
}); //close each(
$(xml).find('parent_rep_detail').each(function(){
return_text = return_text + '<tr><td>';
//if ($(this).attr('image') != '') { 	return_text = return_text + '<img src=/images/reps/' + $(this).attr('image') + ' />';	}
return_text = return_text + '</td><td bgcolor="#e1dbd3"><div class="rep_data">';		 
return_text = return_text + '<div>' + $(this).attr('role') + '</div>';
return_text = return_text + '<b>' + $(this).attr('name') + '</b><br />';
if ($(this).attr('phone') != '') { 	return_text = return_text + 'Phone: ' + $(this).attr('phone') + '<br />';	}
else if ($(this).attr('cell') != '') { return_text = return_text + 'Cell: ' + $(this).attr('cell') + '<br />'; }
//if ($(this).attr('fax') != '') { return_text = return_text + 'Fax: ' + $(this).attr('fax') + '<br />'; }
if ($(this).attr('email') != '') { return_text = return_text + '' + $(this).attr('email') + '<br />'; }
return_text = return_text + '</div></td></tr></table>';
}); //close each(

//$("input#zip").val("");

$("#rep_detail").html(return_text);
$("#rep_detail").slideDown();
}
}); //close $.ajax

}

}else{
$("#rep_detail").slideUp();	
}

return false;
});
	

$(".faq_question").click(function() {
var qindex = $(".faq_question").index(this);
$(".faq_answer:eq(" + qindex + ")").slideToggle();					 
});


//fix for change() event and ie
$(function () {
    if ($.browser.msie) {
        $('input:checkbox').click(function () {
            this.blur();
            this.focus();
        });
    }
});
	

$('.cad_check_box').change(function() {
var v_id=$(this).val();
var dataString = 'id=' + v_id; // + '&phone=' + phone;   
//alert(v_id); 

$.ajax({   
  type: "GET",   
  url: "/resources/downloads_update.aspx",   
  data: dataString,  
  success: function(xml) { 
	$(xml).find('message').each(function(){
	var msg = $(this).attr('id');
if (msg=='failed') {

}else if (msg=='added') {
		var v_int = parseInt($('#item_count').text());
$('#item_count').text(v_int + 1);
}else{
var v_int = parseInt($('#item_count').text());
$('#item_count').text(v_int - 1);
}
});
}   
});

});


$("input#enews_email").focus(function(){
	$(this).attr("value", "");
});


/*$("#signup_submit").click(function(event){
var email=$("input#enews_email").val();
if (email!="") {
var dataString = 'contact_email=' + email; // + '&phone=' + phone;   
//alert (dataString);return false;   


$.ajax({   
  type: "POST",   
  url: "/contact/contact_newsletter.aspx",   
  data: dataString,  
  success: function(xml) { 
	$(xml).find('message').each(function(){
	var msg = $(this).attr('id');
	if (msg=='failed') {
	$("input#enews_email").val("Error. Please try again");
	}else{
	$("input#enews_email").val("Thank You!");	
	//$('#signup_form').html("<div id='message'><p>Thank You!</p></div>");
	}
	});
  
  }   
});
}
return false;
});  */


		
}); // end ready

