// JavaScript Document
//want $ to work with other libs

$(document).ready(noselect);

function noselect(){	
	// $(disableSelection(document.getElementById("imageflow")))
	if ( $("#imageflow").length > 0 ) {
		$(disableSelection("#imageflow"));
	}
};

$(document).ready(sidebar).ready(redirectForAgencyFilter).ready(showMap).ready(clearBlankULs).ready(cleanUpMacroPs).ready(locationFilter);

function clearBlankULs(){
  $('ul:empty').hide();
}

function locationFilter(){
var url = document.location.href.split('?')[0];	 

  $('.locationFilter select').each(function(){
 	$(this).change(function(){
	 var selectedValue = $(this).val();	
	 var fullURL = url + '?filterID=' + this.id + '&location=' + selectedValue;
	 //alert(fullURL);
	 document.location.href = fullURL;
	})
     }
   );
}


//when u add contnt with image via macro u get p's around image
function cleanUpMacroPs(){
  $('.contact-us p:eq(1)').before($('p img'));
  $('.contact-us p:eq(0)').remove();
}

function sidebar(){
    $("#sidebar1,#innercontent").equalizeCols(0);
};

function showMap(){
	var showImage="/media/39592/expand_blue.jpg";
	var hideImage="/media/39939/collapse_blue.jpg";
	var showText="View location";
	var hideText="Hide map";

	$("#mapHolder").css('display', "none");
	
	$("#expander, #showMapText").click(function(){
	  $("#mapHolder").slideToggle("slow");
      	    if($("#expander").attr('src').indexOf(showImage)!=-1){
		    $("#expander").attr('src',hideImage);
		    $('#showMapText').text(hideText);	    
	    }
	    else{
  		    $("#expander").attr('src',showImage);		    
		    $('#showMapText').text(showText);
	    }
 	});
}

function redirectForAgencyFilter(){
  $('#search').click(function(){
	document.location.href=document.location.href.split('?')[0] + '?skill=' + encodeURIComponent($('#skill option:selected').val()) + "&amp;sector=" +encodeURIComponent($('#sector option:selected').val()) + "&amp;location=" + encodeURIComponent($('#geography option:selected').val()) ;

  });
}

//used by filter drop down 
//$(document).ready(filterRedirect);
function filterRedirect(){

	$('#filter').change(function(){

		document.location.href=document.location.href.split('?')[0] + '?filter=' + encodeURIComponent($('#filter option:selected').val());
	 //have to do this to stop the post back which occurs
	 //return false;
 });

};

$(document).ready(memberSitesRedirect);
function memberSitesRedirect(){

	$('#memberSites').change(function(){
		window.open($('#memberSites option:selected').val());
 });

};


//
$(document).ready(redirectToStockistsSearch);
function redirectToStockistsSearch(){
  $('#stockistSearch').click(function(){
	//if($('#location option:selected').val()!='' && $('#location option:selected').val()!='Please select filter'){
  	  document.location.href = $('#searchFormRedirect').val() + "?location=" + encodeURIComponent($('#location option:selected').val());
	//}
	//else{
	//	alert("Please select location");
	//}
     }
  );
}

$(document).ready(alterTable);
function alterTable()
{
 $('span:contains("(not shown)")').hide();
 $('span:contains("optional")').hide();
 $('fieldset p:eq(2) input').after("<br />&nbsp;(optional - remember http://)<br /><br />");
 $('fieldset p:eq(1) input').after("<br />&nbsp;(Personalise your comments with a <a href=\"http://en.gravatar.com\" target=\"blank\" title=\"Get yourself a Gravatar\">Gravatar</a>)<br /><br />");

}

