﻿$(document).ready(function(){
	$("#searchBox :text").labelify({text: "label"});
	$("#searchButton").click("lookupAjax();");

	$('.email').emailLinks();
	$('.aj-paging a').live('click', function(){
		
		if($(this).attr("onclick") != undefined) {return;}		
		
		try{
			var href = $(this).attr('href');
			var box = $(this).parent().parent().parent().parent();
			var panel = $(this).parent().parent().parent();
			var data;
			var url = href + " #" + panel.attr('id');
			$(box).load(url,function(){
				scrollToID('#body');
			});
			
			
		}catch(e){
			alert(e);
		}
		
		return false;
	});

});
function scrollToID(id){

try{
		      var $target = $(id);
		      $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		      if ($target.length) {
		        var targetOffset = $target.offset().top - 94;
		        $('html,body')
		        .animate({scrollTop: targetOffset},{duration: 600, easing:'easeInSine'});
		       
		      }
}catch(e){
		alert("scrollToID() " + e.message);
		}
}
function setHeight(id)
{
	
	var obj = $('#' + id);
	
	var img = obj.find('img');
	
	obj.parent().height(img.height());
}

function wFlash(id,movie)
{
	var params = {};
       	var flashvars = {};
       	var url = movie;
       	
       	params.allowfullscreen = "true";
       	params.allowscriptaccess = "true";
        params.wmode = "transparent"; 
                            
       	swfobject.embedSWF(url, id, "100%", "100%", "10.0.0" ,false,flashvars,params);
}

function wflickrJSON(id,url)
{
    $.getJSON(url,
        function(data){
          $.each(data.items, function(i,item){
            $("<img/>").attr("src", item.media.m).appendTo("#"+id);
            if ( i == 1 ) return false;
          });
        });

}

 function findValue(li) {
if( li == null ) return alert("No match!");

// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];

// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;

alert("The value you selected was: " + sValue);
}

function selectItem(li) {
findValue(li);
}

function formatItem(row) {
return "<a href='default.aspx?id=" + row[1] + "' title='" + row[0]  + "'>"+ row[0] + "</a>";
}

function lookupAjax(){
var oSuggest = $("#searchword")[0].autocompleter;
oSuggest.findValue();
return false;
}

function lookupLocal(){
var oSuggest = $("#searchword")[0].autocompleter;
oSuggest.findValue();

return false;
}

jQuery.fn.flowScroll = function() 
{
	this.find("a[href^=#]").click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		    && location.hostname == this.hostname) {
		      var $target = $(this.hash);
		      $target = $target.length && $target 
		      || $('[name=' + this.hash.slice(1) +']');
		      if ($target.length) {
		        var targetOffset = $target.offset().top - 94;
		        $('html,body')
		        .animate({scrollTop: targetOffset},{duration: 600, easing:'easeInSine'});
		       return false;
		      }
		    }
	     });
}

jQuery.fn.emailLinks = function()
{
    	try{
		var sEmail = this.text();
		sEmail = sEmail.replace("[at]","@").toLowerCase();
		this.hide();
		this.after('<a href="mailto:' + sEmail + '">' + sEmail + '</a>');
		this.remove();

	}
	catch(e){ }

}