$(document).ready(function(){
  var userAgent = navigator.userAgent.toLowerCase();
  $.browser.chrome = /chrome/.test(userAgent);
  $.browser.safari = /webkit/.test(userAgent) && !/chrome/.test(userAgent);
  $('.custom-checks input').customInput();
  $('div.custom-radios input').customInput();
  if (window.location.pathname.match(/search.php|list_category.php|portfolio.php/))
	  $('.sel_search').change(function(){
		if ($('#adv_search_form_div:visible').length){
			$('#adv_search_form').submit()
			return
		}
		var ss = window.location.search.replace(/\?/, '').split('&')
		var sn = ['sorting='+ this.value]
		var rp = /query=.+|search_photos=\d|search_vectors=\d|nudity=\d|id=\d/
		for (i in ss){
			if(rp.test(ss[i]))
				sn.push(ss[i])
		}
		window.location.search = '?'+ sn.join('&')
	  })
});

function change_color(hex)
{
	document.getElementById('color').value=hex;
	document.getElementById('color_view').style.backgroundColor=hex;
	document.getElementById('color_view').style.backgroundImage='';
}

function update_color()
{
	if (document.getElementById('color').value.length!=7) return false;
	document.getElementById('color_view').style.backgroundColor=document.getElementById('color').value;
	document.getElementById('color_view').style.backgroundImage='';
}

function unset_color()
{
	document.getElementById('color_view').style.backgroundColor='';
	document.getElementById('color_view').style.backgroundImage='url(<?=$img_path?>no_color.jpeg)';	
	document.getElementById('color').value='';
}

function update_open_advanced_search()
{
	var open_advanced_search = document.getElementById('open_advanced_search')
	if (open_advanced_search.value==0) open_advanced_search.value=1;
	else if (open_advanced_search.value==1) open_advanced_search.value=0;
}

function setup_searchbox_hints() {
	var thisFn = arguments.callee;
	
	if (!thisFn.applied)
		thisFn.applied = true;
	else
		return;
	
	$(function(){
		$('.sbtn').hover(
			function(e) {
				showPH(e, 'shpop')
			},
			function(e) {
				hidePH(e, 'shpop')
			}
		)
	})
}