/* Author: Joe Kaiser

*/

$(window).load(function() {
	$('.installed a').colorbox();
	$('table.products a').colorbox({
		title: function() {
			var quotepage = '';
			if($('table.products').hasClass('molded_grating')) {
				quotepage = 'grating.asp';
			} else if($('table.products').hasClass('pultruded_grating')) {
				quotepage = 'grating.asp';
			}
			return '<a href="/beta/quotes/' + quotepage + '?product=' + $(this).attr('rel') + '">Request a quote for pricing info!</a>'
		}
	});
	
	$('.grating_colors input').click(function() {
		if($('#custom_grating').is(':checked')) {
			$('#custom_color').removeAttr('disabled');
		} else {
			$('#custom_color').attr('disabled', 'disabled');
			$('#custom_color').val('');
		}
	});
	
	$('#moldedType').change(function() {
		$('#molded_image').attr('src', '/images/' + $('#moldedType').val() + '_small.gif');
		$('#molded_image').show();
	});
	
	$('#pultType').change(function() {
		$('#pultruded_image').attr('src', '/images/' + $('#pultType').val() + '_small.gif');
		$('#pultruded_image').show();
	});
	
	var product = $.getUrlVar('product');
	
	if( product !== undefined) {
		var productType = product.split('_')[0];
		if(productType === 'pultrudedProfile') {
			$('#selPul').attr('checked', 'checked');
			$('#pultType').val(product);
			$('#pultruded_image').attr('src', '/images/' + product + '_small.gif');
			$('#pultruded_image').show();
		} else if(productType = 'pultrudedProfile') {
			$('#selMolded').attr('checked', 'checked');
			$('#moldedType').val(product);
			$('#molded_image').attr('src', '/images/' + product + '_small.gif');
			$('#molded_image').show();
		}
	}
	
	$('#found').change(function(){
		if($(this).val() === 'Other') {
			$('input.grating_other').show();
		} else {
			$('input.grating_other').hide();
		}
	});
	if($(this).val() === 'Other') {
		$('input.grating_other').show();
	} else {
		$('input.grating_other').hide();
	}
	
});

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
