//global scripts

//toggle for quick links on home page
$(document).ready(function(){
	$(".quick-links p").click(function () {
	      //$(".quick-links-select ul").toggle();
	      var quickLinkItems = document.getElementById("QuickLinkItems");
	      
	      if (quickLinkItems != null) {
			if (quickLinkItems.style.display == "none")
				quickLinkItems.style.display = "block";
			else
				quickLinkItems.style.display = "none";
	      }
		 });
 
	
//image slidr
if (!window.devicePixelRatio)
{
	$('.slidr').cycle({ 
				timeout: 30, 
        		speed:   5000,
        		startingSlide: 0,
        		cleartype:  1,
        		speedIn: 60,
        		speedOut: 60 
		});
}

/*    
$('.safari .slidr').cycle({ 
			timeout: 0, 
        	speed:   0,
        	startingSlide: 0,
        	cleartype:  1,
        	speedIn: 0,
        	speedOut: 0 
    });*/
	/*$('#goto1').click(function() { 
	$('.slidr').cycle(0); 
	return false; 
 	});
	$('#goto2').click(function() { 
    $('.slidr').cycle(1); 
	$(this).hide()
    return false; 
    });*/

//accordion
 $("#accordion").accordion({ autoHeight: false });
		
//input hide
	$('.contact-us p:not(.show)').hide();
	$('.contact-us table:not(.show)').hide();
	$(".contact-us input:first").focus(function () {
				$('.contact-us p').show();
				$('.contact-us table').show();
						});
		$(".close-form a").click(function(){
		        $('.contact-us table:not(.show)').toggle();
				$('.contact-us p:not(.show)').hide();
					return false;
					});
									

//hide values in input fields
    var active_color = '#000'; // Colour of user provided text
	var inactive_color = '#999'; // Colour of default text

	$(document).ready(function() {
		  $("input.default-value,  textarea.default-value").css("color", inactive_color);
		  var default_values = new Array();
		  $("input.default-value, textarea.default-value").focus(function() {
		    if (!default_values[this.id]) {
		      default_values[this.id] = this.value;
		    }
		    if (this.value == default_values[this.id]) {
		      this.value = '';
		      this.style.color = active_color;
		    }
		    $(this).blur(function() {
		      if (this.value == '') {
		        this.style.color = inactive_color;
		        this.value = default_values[this.id];
		      }
		    });
		  });
		});
		// hint for input boxes
		jQuery.fn.hint = function (blurClass) {
		  if (!blurClass) { 
		    blurClass = 'blur';
		  }

		  return this.each(function () {
		    // get jQuery version of 'this'
		    var $input = jQuery(this),

		    // capture the rest of the variable to allow for reuse
		      title = $input.attr('title'),
		      $form = jQuery(this.form),
		      $win = jQuery(window);

		    function remove() {
		      if ($input.val() === title && $input.hasClass(blurClass)) {
		        $input.val('').removeClass(blurClass);
		      }
		    }

		    // only apply logic if the element has the attribute
		    if (title) { 
		      // on blur, set value to title attr if text is blank
		      $input.blur(function () {
		        if (this.value === '') {
		          $input.val(title).addClass(blurClass);
		        }
		      }).focus(remove).blur(); // now change all inputs to title

		      // clear the pre-defined text when form is submitted
		      $form.submit(remove);
		      $win.unload(remove); // handles Firefox's autocomplete
		    }
		  });
		};
		
		//call hint for input boxes
	$('.ms-sbcell input').hint(); //TODO: re-address this behavior - Press Release and Event creation is being compromised because of this line of code
}); 
//end jquery


// Routines for Press and Events Listing pages
$(document).ready(function() {
    
    if($('#CategorySelector'))
    {
        $('#CategorySelector').change(function()
        {
            // Update query string
            var newQS = "?category=" + $(this).val();;
            var qs = window.location.search.replace(/\?/, '');
            if(qs.length > 0)
            {
                var splitQS = qs.split('&');
                $.each(splitQS, function()
                {
                    if(this.indexOf("date") >= 0)
                        newQS += "&" + this;
                });
            }
            
            window.location.href = window.location.pathname + newQS;
        });
    }
});

// Routine for Google Map
$(document).ready(function ()
{
    if($('#GoogleMapDiv'))
    {
        /*
        //$("<script" + " src=\"http://maps.google.com/maps?file=api&amp;v=1&amp;key=ABQIAAAAvttmS2-US2sAlcQzSp5OAxQJYO8jd7A89-NztTBXwk9OFeA_5hS4fBNkLx00PNKtr03boOQKdq8r7A\" type=\"text/javascript\"></script>").appendTo('head');
        var scriptBlock = $("<script></script>");
        scriptBlock.attr({
            type: "text/javascript",
            src: "http://maps.google.com/maps?file=api&amp;v=1&amp;key=ABQIAAAAvttmS2-US2sAlcQzSp5OAxQJYO8jd7A89-NztTBXwk9OFeA_5hS4fBNkLx00PNKtr03boOQKdq8r7A"
        });
        scriptBlock.appendTo("head");

        $('#GoogleMapDiv').empty();
        
        if (GBrowserIsCompatible()) 
        {
            var map = new GMap(document.getElementById("GoogleMapDiv"));
            
            GEvent.addListener(map, 'moveend', function() 
            {
		        var center = map.getCenterLatLng();
		        var latLngStr = '(' + center.y + ', ' + center.x + ')';
		        //document.getElementById("message").innerHTML = latLngStr;
	        });
	        
	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());
	        map.centerAndZoom(new GPoint(-83.276367, 32.62087), 11);
	    }
        //  style="WIDTH: 530px; HEIGHT: 370px"
        */
    }
});