// JavaScript Document

var rvalue, value, shownum = 7, subs = 5;

if (document.images)
   {
     pic1on= new Image(256,186);
     pic1on.src="images/category_hover.png";
	 pic1off= new Image(256,186);
     pic1off.src="images/category.png";
   }
   
function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	rvalue = randomstring;
}

function getXHTTP() {
  var xhttp;
   try {   // The following "try" blocks get the XMLHTTP object for various browsers…
      xhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
 		 // This block handles Mozilla/Firefox browsers...
	    try {
	      xhttp = new XMLHttpRequest();
	    } catch (e3) {
	      xhttp = false;
	    }
      }
    }
  return xhttp; // Return the XMLHTTP object
}

function send(obj) {
	var visitor = document.getElementById("visitor");
	var email = document.getElementById("email");
	var notes = document.getElementById("notes");	
	http = getXHTTP();
	randomString();
	document.getElementById('send_res').style.display = '';
	obj.disabled = true;
	name.disabled = true;
	email.disabled = true;
	notes.disabled = true;
	fixed_notes = notes.value;
	fixed_notes = fixed_notes.replace(/\n/g,'<br />');
	http.open("GET", "send.php?code="+rvalue+"&visitor="+escape(visitor.value)+"&visitormail="+escape(email.value)+"&notes="+escape(fixed_notes), true);
	http.onreadystatechange = function() { get_send_res(visitor, email, notes, obj); }
	http.send(null);
}

function get_send_res(visitor, email, notes, obj) {
	if (http.readyState == 4) {
		var res = http.responseText;
		obj.disabled = false;
		visitor.disabled = false;
		email.disabled = false;
		notes.disabled = false;
		document.getElementById('send_res').innerHTML = res;
	}
}

function reset_form() {
	var visitor = document.getElementById("visitor");
	var email = document.getElementById("email");
	var notes = document.getElementById("notes");
	document.getElementById('send_res').style.display = 'none';
	document.getElementById('send_res').innerHTML = '<img src="images/main_load.gif" width="24" height="24" />';
	visitor.value = '';
	email.value = '';
	notes.value = '';
}

function cover(obj) {
	var name = obj.parentNode.parentNode.getElementsByTagName("div");
	name[4].style.display = 'block';
}

function sw(num) {
	i = 0;
	var die = cnum = -1;
	while (i < shownum) {
		if (num != i) {
			if (document.getElementById("a"+i).className == "tab_select")
				die = i;
			document.getElementById("a"+i).className = "a"+i;
		}
		if (num == i) {
			cnum = i;
		}
		i++;
	}
	if (die >= 0) {
		$("#show_"+die+',p').fadeOut(250);
	}
	$("#show_"+cnum+',p').fadeIn(1000);
	document.getElementById("a"+cnum).className = "tab_select";
}

$(function() {
	$('#windows, #doors, #other').click(function(){
		 $(this).find('.cover').css('display', "block");
	});
	
	$('#windows, #doors, #other').hover(function(){
		if ($(this).attr('id') == 'windows') mt = -42; else if ($(this).attr('id') == 'doors') mt = -40; else if ($(this).attr('id') == 'other') mt = -50;
		$(this).find('.category').css('backgroundImage', "url('"+pic1on.src+"')");
		$(this).find('.bck_photo').animate({marginTop: (mt + 21) + "px"},{queue:false,duration:250});
	}, function(){
		$(this).find('.category').css('backgroundImage', "url('"+pic1off.src+"')");
		$(this).find('.bck_photo').animate({marginTop: mt + "px"},{queue:false,duration:400});
		$(this).find('.cover').css('display', 'none');
		expand(-1);
	});
	
	$(".warranty0").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty1").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty2").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty3").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty4").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty5").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty6").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty7").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty8").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty9").colorbox({transition:"none", width:"600px", height:"500px"});
	$(".warranty10").colorbox({transition:"none", width:"600px", height:"500px"});
});

function expand(num) {
	i = 0;
	while (i < subs) {
		if (i != num)
			$("#expand_"+i).slideUp();			
		i++;
	}
	
	if (num >= 0)
		$("#expand_"+num).slideDown();	
}
