$(function(){
	//custom select boxes
	$('.customDD').bind('click', showOptions);
	$('.customDD div.options ul li').bind('click', changeOptions);
	$('.customDD').bind('mouseleave', hideOptions);
	$('#commitToProjectSearch').bind('click', commitToProjectSearch);
});


function showOptions(event){
	var thisObj = $(this);
	var thisObjClass = "customDD"
	var thisObjId = thisObj.attr('id');
	var allOptions = $('.' + thisObjClass + ' div.options');
	var thisObjOptions = $('#' + thisObjId + ' div.options');
	
	allOptions.slideUp(50);
	
	if(thisObjOptions.css('display') == 'block'){
		thisObjOptions.slideUp(50);
	}else{
		thisObjOptions.slideDown(50);
	}
}

function hideOptions(event){
	var thisObj = $(this);
	var thisObjClass = "customDD"
	var allOptions = $('.' + thisObjClass + ' div.options');
	
	allOptions.slideUp(50);
}
function changeOptions(event){
	var thisObj = $(this);
	var thisObjText = thisObj.text();
	var thisObjValueId = thisObj.attr('valueId');
	var thisObjId = thisObj.parent().parent().parent().attr('id');
	var newText = $('#' + thisObjId + ' div.selectedOption p');
	var newValueId = $('#' + thisObjId + ' div.selectedOption');
	
	newValueId.attr('valueId', thisObjValueId);
	newText.text(thisObjText);
}


function commitToProjectSearch(){
	var thisIndustryVal = $('#industry .selectedOption').attr('valueid');
	var thisRegionVal = $('#region .selectedOption').attr('valueid');
	
	if(thisIndustryVal != 0 || thisRegionVal != 0){
		window.location = "/Get_To_Know_Us/Our_Work#markets(" + thisIndustryVal + ")|geography(" + thisRegionVal + ")|";
		//window.location = "/Projects#projectType(15)|markets(6)|geography(5)|"
	}else{
		alert("Please select an Industry and/or Region to search.");
	}
}
