$(document).ready(function() {
	
	if($("#search #query").length) {
		if($("#search #query").val() == '') {
			$("#search #query").val('search');
		}
		$("#search #query").focus(function(){
			if (this.value == 'search') {
				this.value='';
			}
		});
		
		$("#search #query").blur(function(){
			if (this.value == '') {
				this.value='search';
			}
		});
	}
	
	 $('#slideshow').cycle({
	    fx:     'fade',
	    speed:   400,
	    timeout: 5000,
	    pager:  '.slideshow_buttons',
	    pause: true,
		pauseOnPagerHover: true,
	    pagerAnchorBuilder: function(idx, slide) {
	        // return sel string for existing anchor
	        return '.slideshow_buttons li:eq(' + (idx) + ') a';
	    }
	});
	
	$(".contact").colorbox({width:"740px", height:"70%", initialWidth:100, initialHeight:100, iframe:true, href:'/contact/'});
	
	$(".colorbox").colorbox({href: function(){
    	$(this).attr('href');}, initialHeight:"50px", initialWidth:"50px", maxHeight:"70%", maxWidth:"600px", transition:"none", opacity:.8});
    	
	
	// NAVIGATE TO COUNTRY ONCHANGE
    $('select[name="country_select"]').datacenter_country_select();
    
    $('select[name="country_select_home"]').change(function(){
        window.location = 'http://improveagriculture.com/country-snapshots/'+$(this).val();
    });
    
    $('#Country').selectbox();
	
	$("div.blurb .comment").click(function(){
		if($('.commentForm').is(":visible") == false) {
			$('.commentForm').slideToggle('fast');
			$('.addComment').hide();
		}
		return true;
	});
	
	$(".commentForm").hide();
	$('.addComment').click(function(){
		$('.commentForm').slideToggle('fast');
		$(this).hide();
		return false;		
	});

	$('.submitBtn.comment').submit(function(){
		$('.commentForm').hide();
		$('.addComment').show();
		return false;		
	});
	
	$("a[href^='http:']").not("[href*='improveagriculture.com']").attr('target','_blank'); 
	
	
		//if (document.cookie.indexOf('visited=true') === -1) {
		//		
		//	var expires = new Date();
		//	expires.setDate(expires.getDate()+9999);
		//	document.cookie = "visited=true; expires="+expires.toUTCString()+"; path=/";
			    	
		//	var _gaq = _gaq || [];
  		//	_gaq.push(['_setAccount', 'UA-9806754-1']);
		//	_gaq.push(['_trackPageview', '/survey/']);
		
	    //	$(".take-survey").colorbox({width:"600px", height:"570px", initialWidth:100, initialHeight:100, iframe:true, scrolling:true, href:'/survey/', open:true});
	    //} 	

	    //$(".survey-complete").colorbox({width:"600px", height:"570px", initialWidth:100, initialHeight:100, iframe:true, scrolling:true, href:'/survey/thank_you/', open:true});

});


