$(document).ready(function(){
	
$(".rounded").append("<div class='top-left' /><div class='top-right' /><div class='bottom-left' /><div class='bottom-right' />");
$(".roundedpanel").append("<div class='top-cap' /><div class='bottom-cap' />");

/* Add class to inputs so we can style them in IE6 */
$("input[type=submit],input[type=button]").addClass("button");
$("input[type=text]").addClass("text");
$("input[type=password]").addClass("password");
	
if ($('#home-business').length > 0) { /* Check if element exists */
  $("#home-business .wrapper").append("<div class='top-cap' /><div class='bottom-cap' />");
}

/* Toggle between home and business forms in registration page */
$("input#home").click(function() {
		$("fieldset#business").css("display","none");
		$("fieldset#household").css("display","block");
});
$("input#business").click(function() {
		$("fieldset#business").css("display","block");
		$("fieldset#household").css("display","none");
});

  if($(".addAjaxToPhpHref").length>0){
    $(".addAjaxToPhpHref").each(function(i){
      $(this).attr('href', $(this).attr('href') + (($(this).attr('href').indexOf('.php?')>0) ? '&' : '?')+"ajax=1"); 
    });
  }
		$(".tabs").tabs({
		  cache: true,
			ajaxOptions: {
			  //url = url+'&test=1',
				error: function(xhr, status, index, anchor) {
					$(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
				}
			},
      load: function(event, ui) {
        //console.log(event);
        $(ui.panel).addClass('wrapper noMiddleBorders').addClass($('.ui-tabs-panel-class',ui.panel).html());                
        $(ui.panel).append("<div class='top-cap' /><div class='bottom-cap' />");
        $('.ajaxFancyBox').each(function(){ // reinicialize ajax
          $(this).fancybox(fancyoptions);
        });    
      }/*,
      select: function(event, ui) {
        var url = $.data(ui.tab, 'load.tabs');
        if( url ) {
            location.href = url;
            return false;
        }
        return true;
      }  
*/          
		});
$('.tabs').bind('tabsshow', function(event, ui) {
  if(typeof map_all != "undefined" && map_all != null)
    google.maps.event.trigger(map_all, 'resize');
  if(typeof map_household != "undefined" && map_household != null)
    google.maps.event.trigger(map_household, 'resize');
  if(typeof map_business != "undefined" && map_business != null)
    google.maps.event.trigger(map_business, 'resize');
});
if ($('.tabs').length > 0) { /* Check if element exists */
  $(".tabs .wrapper").append("<div class='top-cap' /><div class='bottom-cap' />");
	$(".tabs h3").append("<span></span>");
	$(".tabs .contents li a").append("<div class='top-left' /><div class='top-right' /><span></span>");
}

$(".row").append("<div class='clear-float' />");
// ie display issue on index
$(".float-fix").prepend("<span class='clear' />");

$("li").hover(function() {
  $(this).addClass("hover");										  
},function() {
  $(this).removeClass("hover");	
});

if ($('#offered-wanted').length > 0) { /* Check if element exists */
	var $this = $(this);
	$("#offered-wanted h2").append("<div class='top-left' /><div class='top-right' />");
	
	$("#offered-wanted .wrapper").append("<div class='top-cap' /><div class='bottom-cap' />");

	$("#offered-wanted h2").hover(function() {
		$(this).addClass("hover");										  
	},function() {
		$(this).removeClass("hover");	
	});

	$("#offered-wanted h2").focus(function() {
		var $this = $(this);
		$(".wrapper, #offered-wanted h2").removeClass("active");
		$this.addClass("active");
		$this.next(".wrapper").addClass("active");
	});
	$("#offered-wanted h2").blur(function() {
		var $this = $(this);
		$(".wrapper, #offered-wanted h2").removeClass("active");
		$this.addClass("active");
		$this.next(".wrapper").addClass("active");
	});
}
	
	// add tool tips to .tt-target/.tt-content pairs
    	$(".tt-target").each(function() {
		var link_id = $(this).attr("id");
		link_id = link_id.substr(link_id.lastIndexOf("-")+1);
		$(this).tooltip({
    			bodyHandler: function() {
    				return $($("#tt-content-" + link_id)).html();
    			},
    			showURL:true,
    			fade:true,
    			delay:100,
    			top:5,
    			left:5
    		});
    	});
// Close document ready
});
