this.imagePreview = function(){	
	/* CONFIG */
		
		//xOffset = 10;
		//yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
$("img.preview").hover(function(e){
    this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.src +"' alt='Image preview' width='350' />"+ c +"</p>");								 
		$("#preview")     
      .css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
		//$("body").css({'overflow' : 'auto'});
    });	
	$("img.preview").mousemove(function(e){
		$("body").css({'overflow' : 'visible'});
    
    $space = $(window).height() - e.pageY;
    if (($(window).height() - e.pageY) < 350) { 
 $("#preview")
			xOffset = 190;
    }
    else {
      xOffset = 10;

    $("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
		}
	});
};


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 40;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$(".ctooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$(".tooltip").click(function(){
  return false;
  });

  var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}



// starting the script on page load
$(document).ready(function(){
	if (jQuery.url.attr("source") == 'http://www.funeralserviceprogram.com/' || jQuery.url.attr("source") == 'http://funeralserviceprogram.com/' || jQuery.url.attr("source") == 'http://intro.zacharydouglass.com/' || jQuery.url.attr("source") == 'http://www.intro.zacharydouglass.com/') {
    $("#mies1").overlay({onClose: function(event) {
      window.location = "http://www.zacharydouglass.com/"; 
    } ,api: true}).load();        
  }
  /*if (jQuery.url.attr("source") == 'http://zacharydouglass.com/products') {
    $("#monthlydeal").css({'display' : 'none'});       
  } */  
     if (jQuery.url.attr("source") == 'http://www.zacharydouglass.com/pages/newhomepage') {
     
      //$("ul.tabs").tabs("div.panes > div");
      $("ul.tabs").tabs(".scrollpanel > div", { 
 autoplay: true,
 interval: '10000',
        // enable "cross-fading" effect 
        effect: 'fade', 
        fadeOutSpeed: "slow",
 
        // start from the beginning after the last tab 
        rotate: true 
 
    // use the slideshow plugin. It accepts its own configuration 
    }).slideshow();
    $("ul.tabs").tabs().play();
    
       $('#secretarybutton').click(function() {
        return false;
       });
      
      $('#secretarybutton').hover(
        function () {
          $('#secretarybenefits').slideDown(400);
          var x = $(this).offset().top - 220; // 100 provides buffer in viewport
          $('html,body').animate({scrollTop: x}, 500);
        },
        function () {    
          $('#secretarybenefits').slideUp(400);
        }
      );
      
      $('#directorbutton').hover(
        function () {
          $('#directorbenefits').slideDown(400);
           var x = $(this).offset().top - 210; // 100 provides buffer in viewport
          $('html,body').animate({scrollTop: x}, 500);
        },
        function () {    
          $('#directorbenefits').slideUp(400);
        }
      );
      
      $('#familiesbutton').hover(
        function () {
          $('#familiesbenefits').slideDown(400);
           var x = $(this).offset().top - 210; // 100 provides buffer in viewport
          $('html,body').animate({scrollTop: x}, 500);
        },
        function () {    
          $('#familiesbenefits').slideUp(400);
        }
    );
    

    };
    
    
    
  imagePreview();
	tooltip();
	$(window).scroll(function () { 
     imagePreview(); 
    });
  
  
  //$('.scroll-pane').jScrollPane();

  
  $("a[rel]").overlay();

  $(".normaloverlay").overlay();
  
  $(".preview").overlay({
    target: '#templateoverlay',
    closeOnClick: false,
    onBeforeLoad: function(event) { 
        //alert(this.getTrigger().attr("alt"));
        //this.getTrigger().hide();
        //$("body").append('<div id="odiv"><img src="'+ this.getTrigger().attr("alt")+'" /></div>');
        //$("#mies1").empty();
        if (jQuery.url.segment(2) == '6') {
           $("#templateimage").css({'background-color' : '#FFFFFF'});
        }
        
        $("#templateoverlay").append('<div id="templateimage"><img src="'+ this.getTrigger().attr("alt")+'" /></div>');
        if (jQuery.url.segment(2) == '6') {
           $("#templateimage").css({'background-color' : '#FFFFFF', 'text-align' : 'center'});
           $("#templateimage img").css({'margin' : '10px', 'border' : '2px red dotted'});
        } 
    },
    onLoad: function(event) {
      var $id = this.getTrigger().attr("rel");
      $("#templateimage").rightClick( function(e) {
		    //alert("You just right clicked!"+ $id);
		    $.post('/images/view/'+ $id);
      });
    },
    onClose: function(event) {
      $("#templateimage").remove();
       //$("#templateoverlay").append('<div class="close"></div>');
      //$("body").append('<div id="templateoverlay"></div>');  
    }    
    });
$('.iframeOverlay').overlay({ 
        onBeforeLoad: function() {
           $("#videoIframe").attr({src: this.getTrigger().attr("href")});
        }  
    }); 

$(".tooltip").overlay({ 
 
        onBeforeLoad: function() {
           $("#videoIframe").attr({src: this.getTrigger().attr("href")});
        } 
 
    }); 

$('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)

$(document).click(jsddm_close);
$("#homeButtons").overlay().load();

$("#producttip").tooltip({ effect: 'slide'});  


/*if ($('#flashMessage') > 0) {
  $('#flashMessage').hide();
  alert ($('#flashMessage').html());
} */

//------------DD ROUNDIES-----------------//

//$('.button').corner("3px");
		  //$('.submit input').corner("3px");


/*DD_roundies.addRule('.calcDiv, .headerBox, .rounded, .membershipBoxContainer, #goldBox, #silverBox, #bronzeBox, .whiteBox', '10px', true);
      //DD_roundies.addRule('#header', '0, 0, 10px, 10px', true);
      DD_roundies.addRule('.submit input, .button, .normalButton', '3px', true);
      DD_roundies.addRule('#chooseBox', '10px, 0, 0, 10px', true);
      DD_roundies.addRule('#calcFormBox', '0, 10px, 0, 0', true);
      DD_roundies.addRule('#memberBoxBottom', '0, 0, 10px, 10px', true);   
      DD_roundies.addRule('.jScrollPaneDrag  ', '3px', true);  
*/
//------------END DD ROUNDIES-----------------//

  
  //$("img[rel]").overlay();

});