<?php

require_once 'dd.constant.php';

class BaseDD {
	
	//button design
	const BUTTON_DESIGN_NORMAL = 'Normal';
	const BUTTON_DESIGN_COMPACT = 'Compact';
	
	//vote variable
	const VOTE_URL = 'VOTE_URL'; 
	const VOTE_TITLE = 'VOTE_TITLE';
	const VOTE_BUTTON_DESIGN = 'VOTE_BUTTON_DESIGN';
	const SCHEDULER_TIMER = 'SCHEDULER_TIMER';
	const POST_ID = 'POST_ID';
	
	//default value
	const DEFAULT_APPEND_TYPE = 'none';
	const DEFAULT_OPTION_AJAX = 'false';
	const DEFAULT_BUTTON_DESIGN_DROPDOWN_BOX = "Normal,Compact";
	
    // define properties
    var $name; //name of the vote button
    var $baseURL; // vote button URL, before construt
    var $baseURL_lazy; // vote button URL, before construt, lazy version
    var $baseURL_lazy_script; // jQuery script , lazy version
    var $scheduler_lazy_script; //scheduler function
    var $scheduler_lazy_timer; //miliseconds
	
    // contains DD option value, in array
    var $wp_options; 
   
    var $finalURL; //final URL for display, after constructs
    var $finalURL_lazy;//final lazy URL for display, after constructs
    var $finalURL_lazy_script;//final jQuery, after constructs
    var $final_scheduler_lazy_script; //final scheduler, after constructs
    
    var $option_append_type;
	var $option_button_design;
	var $option_button_weight;
	var $option_ajax_left_float;
	var $option_lazy_load;
	 
	var $button_weight_value;
	
	var $button_dropdown_box_value;
	var $normalButtonWH;
	var $compactButtonWH;
	
    /**
     * Construct the default value for digg digg 
     * @param $name name of the vote site
     * @param $baseURL URL for the vote button 
     */
    function BaseDD($name, $baseURL) {
    	$this->name = $name;
    	$this->baseURL = $baseURL;
    	$this->initWPOptions();
    	$this->button_dropdown_box_value = self::DEFAULT_BUTTON_DESIGN_DROPDOWN_BOX;
    }
    
    /**
     * Construct the wordpress options value, save into wp_options
     */
    private function initWPOptions() {
    	$this->wp_options = array();
    	$this->wp_options[$this->option_append_type] = self::DEFAULT_APPEND_TYPE;
    	$this->wp_options[$this->option_button_design] = self::BUTTON_DESIGN_NORMAL;
    	$this->wp_options[$this->option_ajax_left_float] = self::DEFAULT_OPTION_AJAX;
    	$this->wp_options[$this->option_lazy_load] = self::DEFAULT_OPTION_AJAX;
    	$this->wp_options[$this->option_button_weight] = $this->button_weight_value;
    }
    
	/*
     * return the lazy load option
     */
    public function get_lazy_load(){
    	return $this->wp_options[$this->option_lazy_load];
    }

	/*
     * return the ajax left float option
     */
    public function get_ajax_left_float(){
    	return $this->wp_options[$this->option_ajax_left_float];
    }
    
	/*
     * return the button order value
     */
    public function get_button_weight(){
    	return $this->wp_options[$this->option_button_weight];
    }
    
    /*
     * return the append type value
     */
    public function get_append_type(){
    	return $this->wp_options[$this->option_append_type];
    }
    
	/*
     * return the button design value
     */
    public function get_button_design(){
    	return $this->wp_options[$this->option_button_design];
    }
    
    /**
     * Return the button design layout 
     * @param $button button design, normal or compact
     * @return button design
     */
    public function getButtonDesign($button){
    	
    	$result ='';
    	
    	if($button==self::BUTTON_DESIGN_NORMAL){
    		$result = $this->normalButtonWH;
    	}else if ($button==self::BUTTON_DESIGN_COMPACT){
    		$result = $this->compactButtonWH;
    	}else{
    		$result = $this->normalButtonWH;
    	}
    	
    	return $result;
    }
	
    /**
     * @param $url post link
     * @param $title post title
     * @param $button button design
     * 
     */
    public function construstURL($url, $title,$button, $postId){
    	$finalURL = '';
    	
    	//if ajax float, force the button to normal
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL);
    	}else{
    		$finalURL = str_replace(self::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL);
    	}
    	
    	$finalURL = str_replace(self::VOTE_TITLE,$title,$finalURL);
    	$finalURL = str_replace(self::VOTE_URL,$url,$finalURL);
    	$finalURL = str_replace(self::POST_ID,$postId,$finalURL);
    
    	$this->finalURL = $finalURL;
    	
    	//$finalURL_lazy
    	$finalURL_lazy = '';
    	
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL_lazy = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL_lazy);
    	}else{
    		$finalURL_lazy = str_replace(self::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL_lazy);
    	}
    	
    	$finalURL_lazy = str_replace(self::VOTE_TITLE,$title,$finalURL_lazy);
    	$finalURL_lazy = str_replace(self::VOTE_URL,$url,$finalURL_lazy);
    	$finalURL_lazy = str_replace(self::POST_ID,$postId,$finalURL_lazy);
    	
    	$this->finalURL_lazy = $finalURL_lazy;
    	
    	//$finalURL_lazy_script
    	$finalURL_lazy_script = '';
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL_lazy_script);
    	}else{
    		$finalURL_lazy_script = str_replace(self::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL_lazy_script);
    	}
    	$finalURL_lazy_script = str_replace(self::VOTE_TITLE,$title,$finalURL_lazy_script);
    	$finalURL_lazy_script = str_replace(self::VOTE_URL,$url,$finalURL_lazy_script);
    	$finalURL_lazy_script = str_replace(self::POST_ID,$postId,$finalURL_lazy_script);
    	
    	$this->finalURL_lazy_script = $finalURL_lazy_script;
    	
    	//$final_scheduler_lazy_script
    	$final_scheduler_lazy_script = '';
    	$final_scheduler_lazy_script = str_replace(self::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$this->scheduler_lazy_script);
    	$final_scheduler_lazy_script = str_replace(self::POST_ID,$postId,$final_scheduler_lazy_script);
    	
    	$this->final_scheduler_lazy_script =  $final_scheduler_lazy_script;
    	
    }
    
}

//Digg.com properties and methods
class DD_Digg extends BaseDD{
	
	//constant value
	const NAME = "Digg";
	const BASEURL = "<script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton VOTE_BUTTON_DESIGN' href='http://digg.com/submit?url=VOTE_URL&amp;title=VOTE_TITLE'></a>";
	
	const BASEURL_LAZY = "<div class='dd-digg-ajax-load dd-digg-POST_ID'></div><a class='DiggThisButton DD_DIGG_AJAX_POST_ID VOTE_BUTTON_DESIGN'></a>";
	const BASEURL_LAZY_SCRIPT = " function loadDigg_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-digg-POST_ID').remove();\$('.DD_DIGG_AJAX_POST_ID').attr('href','http://digg.com/submit?url=VOTE_URL&amp;title=VOTE_TITLE');\$.getScript('http://widgets.digg.com/buttons.js'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadDigg_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
    
	const OPTION_APPEND_TYPE = "dd_digg_appendType";
	const OPTION_BUTTON_DESIGN = "dd_digg_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_digg_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_digg_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_digg_lazy_load";
	
	const NORMAL_BUTTON_WH = "DiggMedium";
	const COMPACT_BUTTON_WH = "DiggCompact";
	const DEFAULT_BUTTON_WEIGHT = "100";
	
	//constructor
    public function DD_Digg() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
	
        parent::BaseDD(self::NAME, self::BASEURL);
    } 
    
}

//Reddit.com properties and methods
class DD_Reddit extends BaseDD{
	
	//constant value
	const NAME = "Reddit";
	const BASEURL = "<script type='text/javascript'>reddit_url = VOTE_URL;reddit_title = VOTE_TITLE;reddit_newwindow='1';</script><script type='text/javascript' src='http://www.reddit.com/static/button/VOTE_BUTTON_DESIGN'></script>";

	const BASEURL_LAZY = "<div class='dd-reddit-ajax-load dd-reddit-POST_ID'></div><iframe class='DD_REDDIT_AJAX_POST_ID' src='#' height='0' width='0' scrolling='no' frameborder='0'></iframe>";
	const BASEURL_LAZY_SCRIPT = " function loadReddit_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-reddit-POST_ID').remove();\$('.DD_REDDIT_AJAX_POST_ID').attr('width','51');\$('.DD_REDDIT_AJAX_POST_ID').attr('height','69');\$('.DD_REDDIT_AJAX_POST_ID').attr('src','http://www.reddit.com/static/button/button2.html?width=51&amp;url=VOTE_URL&amp;title=VOTE_TITLE&amp;newwindow=1'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadReddit_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const OPTION_APPEND_TYPE = "dd_reddit_appendType";
	const OPTION_BUTTON_DESIGN = "dd_reddit_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_reddit_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_reddit_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_reddit_lazy_load";
	
	const NORMAL_BUTTON_WH = "button2.js";
	const COMPACT_BUTTON_WH = "button1.js";
	const DEFAULT_BUTTON_WEIGHT = "99";
	
	
	//constructor
    public function DD_Reddit() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
			
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    } 
    
}


//Google Buzz properties and methods
class DD_GBuzz extends BaseDD{
	
	//constant value
	const NAME = "Google buzz";
	const BASEURL = "<a title='Post on Google Buzz' class='google-buzz-button' href='http://www.google.com/buzz/post' data-button-style='VOTE_BUTTON_DESIGN' data-url='VOTE_URL'></a><script type='text/javascript' src='http://www.google.com/buzz/api/button.js'></script>";

	const OPTION_APPEND_TYPE = "dd_gbuzz_appendType";
	const OPTION_BUTTON_DESIGN = "dd_gbuzz_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_gbuzz_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_gbuzz_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_gbuzz_lazy_load";
	
	//DD_GBUZZ_AJAX_POST_ID
	const BASEURL_LAZY = "<div class='dd-gbuzz-ajax-load dd-gbuzz-POST_ID'></div><a title='Post on Google Buzz' class='google-buzz-button' href='http://www.google.com/buzz/post' data-button-style='VOTE_BUTTON_DESIGN' data-url='VOTE_URL'></a>";
	const BASEURL_LAZY_SCRIPT = " function loadGBuzz_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-gbuzz-POST_ID').remove();\$.getScript('http://www.google.com/buzz/api/button.js'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadGBuzz_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const NORMAL_BUTTON_WH = "normal-count";
	const COMPACT_BUTTON_WH = "small-count";
	const DEFAULT_BUTTON_WEIGHT = "98";
	
	//constructor
    public function DD_GBuzz() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
    }     
   
}

//dzone.com properties and methods
class DD_Dzone extends BaseDD{
	
	//constant value
	const NAME = "Dzone";
	const BASEURL = "<iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=VOTE_URL&amp;title=VOTE_TITLE&amp;t=VOTE_BUTTON_DESIGN frameborder='0' scrolling='no'></iframe>";
	
	const BASEURL_LAZY = "<div class='dd-dzone-ajax-load dd-dzone-POST_ID'></div><iframe class='DD_DZONE_AJAX_POST_ID' src='#' height='0' width='0' scrolling='no' frameborder='0'></iframe>";
	const BASEURL_LAZY_SCRIPT = " function loadDzone_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-dzone-POST_ID').remove();\$('.DD_DZONE_AJAX_POST_ID').attr('width','52');\$('.DD_DZONE_AJAX_POST_ID').attr('height','68');\$('.DD_DZONE_AJAX_POST_ID').attr('src','http://widgets.dzone.com/links/widgets/zoneit.html?url=VOTE_URL&title=VOTE_TITLE&t=1'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadDzone_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const OPTION_APPEND_TYPE = "dd_dzone_appendType";
	const OPTION_BUTTON_DESIGN = "dd_dzone_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_dzone_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_dzone_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_dzone_lazy_load";
	
	const NORMAL_BUTTON_WH = "1' height='68' width='52'";
	const COMPACT_BUTTON_WH = "2' height='18' width='120'";
	const DEFAULT_BUTTON_WEIGHT = "97";
	          
	//constructor
    public function DD_Dzone() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    } 
    
}

//tweetmeme.com properties and methods
class DD_TweetMeme extends BaseDD{
	
	//constant value
	const NAME = "TweetMeme";
	const BASEURL ="<iframe src='http://api.tweetmeme.com/button.js?url=VOTE_URL&source=VOTE_SOURCE&service=VOTE_SERVICE_NAME&service_api=VOTE_SERVICE_API&style=VOTE_BUTTON_DESIGN frameborder='0' scrolling='no'></iframe>";
	const OPTION_APPEND_TYPE = "dd_tweetmeme_appendType";
	const OPTION_BUTTON_DESIGN = "dd_tweetmeme_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_tweetmeme_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_tweetmeme_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_tweetmeme_lazy_load";
	
	const BASEURL_LAZY = "<div class='dd-tweetmeme-ajax-load dd-tweetmeme-POST_ID'></div><iframe class='DD_TWEETMEME_AJAX_POST_ID' src='#' height='0' width='0' scrolling='no' frameborder='0'></iframe>";
	const BASEURL_LAZY_SCRIPT = " function loadTweetMeme_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-tweetmeme-POST_ID').remove();\$('.DD_TWEETMEME_AJAX_POST_ID').attr('width','50');\$('.DD_TWEETMEME_AJAX_POST_ID').attr('height','61');\$('.DD_TWEETMEME_AJAX_POST_ID').attr('src','http://api.tweetmeme.com/button.js?url=VOTE_URL&source=VOTE_SOURCE&style=normal&service=VOTE_SERVICE_NAME&service_api=VOTE_SERVICE_API'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadTweetMeme_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const NORMAL_BUTTON_WH = "normal' height='61' width='50'";
	const COMPACT_BUTTON_WH = "compact' height='20' width='90'";
    const DEFAULT_BUTTON_WEIGHT = "96";
          
	const VOTE_SOURCE = "VOTE_SOURCE";
	const VOTE_SERVICE_NAME = "VOTE_SERVICE_NAME";
	const VOTE_SERVICE_API = "VOTE_SERVICE_API";
	
	//constructor
    public function DD_TweetMeme() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
    } 
    
    //override the base method to construct the source 
	public function construstURL($url, $source,$button,$postId, $service, $serviceapi){

    	$finalURL = '';
    	
    	//if ajax float, force the button to normal
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL);
    	}else{
    		$finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL);
    	}
    	
    	$finalURL = str_replace(parent::VOTE_URL,$url,$finalURL);
    	$finalURL = str_replace(parent::POST_ID,$postId,$finalURL);
    	$finalURL = str_replace(self::VOTE_SOURCE,$source,$finalURL);
    	$finalURL = str_replace(self::VOTE_SERVICE_NAME,$service,$finalURL);
    	$finalURL = str_replace(self::VOTE_SERVICE_API,$serviceapi,$finalURL);
    
    	$this->finalURL = $finalURL;

    	//$finalURL_lazy
    	$finalURL_lazy = '';
    	$finalURL_lazy = str_replace(parent::POST_ID,$postId,$this->baseURL_lazy);
    	$this->finalURL_lazy = $finalURL_lazy;
    	
    	//$finalURL_lazy_script
    	$finalURL_lazy_script = '';
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL_lazy_script);
    	}else{
    		$finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL_lazy_script);
    	}
    	$finalURL_lazy_script = str_replace(parent::VOTE_URL,$url,$finalURL_lazy_script);
    	$finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
    	$finalURL_lazy_script = str_replace(self::VOTE_SOURCE,$source,$finalURL_lazy_script);
    	$finalURL_lazy_script = str_replace(self::VOTE_SERVICE_NAME,$service,$finalURL_lazy_script);
    	$finalURL_lazy_script = str_replace(self::VOTE_SERVICE_API,$serviceapi,$finalURL_lazy_script);
    	
    	$this->finalURL_lazy_script = $finalURL_lazy_script;
    	
    	//$final_scheduler_lazy_script
    	$final_scheduler_lazy_script = '';
    	$final_scheduler_lazy_script = str_replace(self::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$this->scheduler_lazy_script);
    	$final_scheduler_lazy_script = str_replace(self::POST_ID,$postId,$final_scheduler_lazy_script);
    	
    	$this->final_scheduler_lazy_script =  $final_scheduler_lazy_script;
    	
    }
    
}

//official twitter properties and methods
class DD_Twitter extends BaseDD{
	
	//constant value
	const NAME = "Twitter";
	const BASEURL ="<a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-url=\"VOTE_URL\" data-count=\"VOTE_BUTTON_DESIGN\" data-text=\"VOTE_TITLE\" data-via=\"VOTE_SOURCE\" >Tweet</a><script type=\"text/javascript\" src=\"http://platform.twitter.com/widgets.js\"></script>";
	
	const OPTION_APPEND_TYPE = "dd_twitter_appendType";
	const OPTION_BUTTON_DESIGN = "dd_twitter_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_twitter_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_twitter_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_twitter_lazy_load";
	
	//DD_TWITTER_AJAX_POST_ID
	const BASEURL_LAZY ="<div class='dd-twitter-ajax-load dd-twitter-POST_ID'></div><a href=\"http://twitter.com/share\" class=\"twitter-share-button\" data-url=\"VOTE_URL\" data-count=\"VOTE_BUTTON_DESIGN\" data-text=\"VOTE_TITLE\" data-via=\"VOTE_SOURCE\" ></a>";
	
	const BASEURL_LAZY_SCRIPT = " function loadTwitter_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-twitter-POST_ID').remove();\$.getScript('http://platform.twitter.com/widgets.js'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadTwitter_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";

	const NORMAL_BUTTON_WH = "vertical";
	const COMPACT_BUTTON_WH = "horizontal";
	const DEFAULT_BUTTON_WEIGHT = "98";
	
	const VOTE_SOURCE = "VOTE_SOURCE";
	
	//constructor
    public function DD_Twitter() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
    }

	//override the base method to construct the source 
    public function construstURL($url, $title,$button, $postId,$source){

    	$finalURL = '';
    	
    	//if ajax float, force the button to normal
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL);
    	}else{
    		$finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL);
    	}
    	
    	$finalURL = str_replace(parent::VOTE_TITLE,$title,$finalURL);
    	$finalURL = str_replace(parent::VOTE_URL,$url,$finalURL);
    	$finalURL = str_replace(parent::POST_ID,$postId,$finalURL);
    	$finalURL = str_replace(self::VOTE_SOURCE,$source,$finalURL);
    
    	$this->finalURL = $finalURL;

    	
    	//$finalURL_lazy
    	$finalURL_lazy = '';
    	
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL_lazy);
    	}else{
    		$finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL_lazy);
    	}
    	
    	$finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
    	$finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);
    	$finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
    	$finalURL_lazy = str_replace(self::VOTE_SOURCE,$source,$finalURL_lazy);
  
    	$this->finalURL_lazy = $finalURL_lazy;
    	
    	//$finalURL_lazy_script
    	$finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$this->baseURL_lazy_script);
    	
    	$this->finalURL_lazy_script = $finalURL_lazy_script;
    	
    	//$final_scheduler_lazy_script
    	$final_scheduler_lazy_script = '';
    	$final_scheduler_lazy_script = str_replace(self::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$this->scheduler_lazy_script);
    	$final_scheduler_lazy_script = str_replace(self::POST_ID,$postId,$final_scheduler_lazy_script);
    	
    	$this->final_scheduler_lazy_script =  $final_scheduler_lazy_script;
    	
    }
    
}

//topsy.com properties and methods
class DD_Topsy extends BaseDD{
	
	//constant value
	const NAME = "Topsy";
	const BASEURL = "<div class=\"topsy_widget_data\"><!--{\"url\":\"VOTE_URL\",\"style\":\"VOTE_BUTTON_DESIGN\",\"theme\":\"VOTE_THEME\",\"nick\":\"VOTE_SOURCE\"}--></div>";

	const OPTION_APPEND_TYPE = "dd_topsy_appendType";
	const OPTION_BUTTON_DESIGN = "dd_topsy_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_topsy_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_topsy_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_topsy_lazy_load";
		
	const NORMAL_BUTTON_WH = "big";
	const COMPACT_BUTTON_WH = "compact";
    const DEFAULT_BUTTON_WEIGHT = "96";
          
	const VOTE_SOURCE = "VOTE_SOURCE";
	const VOTE_THEME = "VOTE_THEME";
	
	//constructor
    public function DD_Topsy() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
			
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
    } 
    
    //override the base method to construct the source 
	public function construstURL($url,$button,$source, $theme){

    	$finalURL = '';
    	
    	//if ajax float, force the button to normal
    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
    		$finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL);
    	}else{
    		$finalURL = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL);
    	}
    	
    	$finalURL = str_replace(parent::VOTE_URL,$url,$finalURL);
    	$finalURL = str_replace(self::VOTE_SOURCE,$source,$finalURL);
    	$finalURL = str_replace(self::VOTE_THEME,$theme,$finalURL);
    
    	$this->finalURL = $finalURL;

    }
    
}

//facebook.com properties and methods
class DD_FbShare extends BaseDD{
	
	//constant value
	const NAME = "Facebook Share";
	const BASEURL = "<a name='fb_share' type='VOTE_BUTTON_DESIGN' share_url='VOTE_URL' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script>";
	
	const OPTION_APPEND_TYPE = "dd_fbshare_appendType";
	const OPTION_BUTTON_DESIGN = "dd_fbshare_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_fbshare_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_fbshare_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_fbshare_lazy_load";
	
	const BASEURL_LAZY = "<div class='dd-fbshare-ajax-load dd-fbshare-POST_ID'></div><a class='DD_FBSHARE_AJAX_POST_ID' name='fb_share' type='VOTE_BUTTON_DESIGN' share_url='VOTE_URL' href='http://www.facebook.com/sharer.php'></a>";
	const BASEURL_LAZY_SCRIPT = " function loadFBShare_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-fbshare-POST_ID').remove(); \$.getScript('http://static.ak.fbcdn.net/connect.php/js/FB.Share'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadFBShare_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const NORMAL_BUTTON_WH = "box_count";
	const COMPACT_BUTTON_WH = "button_count";
	const DEFAULT_BUTTON_WEIGHT = "95";
	
	//constructor
    public function DD_FbShare() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
      
    } 
}


//fbshare.me properties and methods
class DD_FbShareMe extends BaseDD{
	
	//constant value
	const NAME = "fbshare.me";
	const BASEURL = "<script>var fbShare = {url: 'VOTE_URL',size: 'VOTE_BUTTON_DESIGN',}</script><script src='http://widgets.fbshare.me/files/fbshare.js'></script>";

	const OPTION_APPEND_TYPE = "dd_fbshareme_appendType";
	const OPTION_BUTTON_DESIGN = "dd_fbshareme_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_fbshareme_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_fbshareme_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_fbshareme_lazy_load";

	const BASEURL_LAZY = "<div class='dd-fbshareme-ajax-load dd-fbshareme-POST_ID'></div><iframe class=\"DD_FBSHAREME_AJAX_POST_ID\" src='#' height='0' width='0' scrolling='no' frameborder='0' allowtransparency='true'></iframe>";
	const BASEURL_LAZY_SCRIPT = " function loadFBShareMe_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-fbshareme-POST_ID').remove();\$('.DD_FBSHAREME_AJAX_POST_ID').attr('width','53');\$('.DD_FBSHAREME_AJAX_POST_ID').attr('height','69');\$('.DD_FBSHAREME_AJAX_POST_ID').attr('src','http://widgets.fbshare.me/files/fbshare.php?url=VOTE_URL&size=large');  }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadFBShareMe_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const NORMAL_BUTTON_WH = "large";
	const COMPACT_BUTTON_WH = "small";
	const DEFAULT_BUTTON_WEIGHT = "95";
	
	//constructor
    public function DD_FbShareMe() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
      
    } 
}

//facebook.com properties and methods
class DD_FbLike extends BaseDD{
	
	//constant value
	const NAME = "Facebook Like";
	const BASEURL = "<iframe src='http://www.facebook.com/plugins/like.php?href=VOTE_URL&amp;VOTE_BUTTON_DESIGN scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:25px;' allowTransparency='true'></iframe>";
	
	const OPTION_APPEND_TYPE = "dd_fblike_appendType";
	const OPTION_BUTTON_DESIGN = "dd_fblike_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_fblike_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_fblike_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_fblike_lazy_load";
	
	const BASEURL_LAZY = "<div class='dd-fblike-ajax-load dd-fblike-POST_ID'></div><iframe class=\"DD_FBLIKE_AJAX_POST_ID\" src='#' height='0' width='0' scrolling='no' frameborder='0' allowTransparency='true'></iframe>";
	const BASEURL_LAZY_SCRIPT = " function loadFBLike_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-fblike-POST_ID').remove();\$('.DD_FBLIKE_AJAX_POST_ID').attr('width','450');\$('.DD_FBLIKE_AJAX_POST_ID').attr('height','25');\$('.DD_FBLIKE_AJAX_POST_ID').attr('src','http://www.facebook.com/plugins/like.php?href=VOTE_URL&amp;show_faces=false'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadFBLike_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const LIKE = "layout=button_count' width='90px'";
	const LIKE_TEXT = "layout=standard' width='450px'";
	const LIKE_TEXT_FACE= "layout=standard&amp;show_faces=true' width='450px'";
	
	const RECOMMEND = "action=recommend&amp;layout=button_count' width='140px'";
	const RECOMMEND_TEXT = "action=recommend&amp;layout=standard' width='450px'";
	const RECOMMEND_TEXT_FACE = "action=recommend&amp;layout=standard&amp;show_faces=true' width='450px'";
	
	const DEFAULT_BUTTON_WEIGHT = "94";
	
	const BUTTON_DROPDOWN_BOX_VALUE = "Like,Like + Text,Like + Text + Face,Recommend,Recommend + Text, Recommend + Text + Face";
	
	//constructor
    public function DD_FbLike() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		//$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		//$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
        $this->button_dropdown_box_value = self::BUTTON_DROPDOWN_BOX_VALUE;
    } 
    
	public function getButtonDesign($button){
    	
    	$result ='';
    	
    	if($button=="Like"){
    		$result = self::LIKE;
    	}else if ($button=="Like + Text"){
    		$result = self::LIKE_TEXT;
    	}else if ($button=="Like + Text + Face"){
    		$result = self::LIKE_TEXT_FACE;
    	}else if ($button=="Recommend"){
    		$result = self::RECOMMEND;
    	}else if ($button=="Recommend + Text"){
    		$result = self::RECOMMEND_TEXT;
    	}else if ($button=="Recommend + Text + Face"){
    		$result = self::RECOMMEND_TEXT_FACE;
    	}else{
    		$result = self::LIKE;
    	}
    	
    	return $result;
    }
    
}

//delicious.com properties and methods
class DD_Delicious extends BaseDD{
	
	//constant value
	const NAME = "Delicious";
	
	const BASEURL = "<a href='http://delicious.com/save' onclick=\"window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent('VOTE_URL')+'&amp;title='+encodeURIComponent('VOTE_TITLE'),'delicious', 'toolbar=no,width=550,height=550'); return false;\">VOTE_BUTTON_DESIGN</a>";
	
	const OPTION_APPEND_TYPE = "dd_delicious_appendType";
	const OPTION_BUTTON_DESIGN = "dd_delicious_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_delicious_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_delicious_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_delicious_lazy_load";

	const BASEURL_LAZY = "<div class='dd-delicious-ajax-load dd-delicious-POST_ID'></div><a href='http://delicious.com/save' onclick=\"window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent('VOTE_URL')+'&amp;title='+encodeURIComponent('VOTE_TITLE'),'delicious', 'toolbar=no,width=550,height=550'); return false;\">VOTE_BUTTON_DESIGN</a>";
	const BASEURL_LAZY_SCRIPT = " function loadDelicious_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-delicious-POST_ID').remove();\$('.delicious-normal-img,.delicious-compact-img').show();\$.getJSON('http://feeds.delicious.com/v2/json/urlinfo/data?url=VOTE_URL&amp;callback=?',function(data) {var msg ='';var count = 0;if (data.length > 0) {count = data[0].total_posts;if(count ==0){msg = 'Save';}else if(count ==1){msg = '1 save';}else{msg = count + ' saves'}}else{msg = 'Save';}\$('#DD_DELICIOUS_AJAX_POST_ID').text(msg);}); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadDelicious_POST_ID()',SCHEDULER_TIMER);\$('.delicious-normal-img,.delicious-compact-img').hide();";
	const SCHEDULER_LAZY_TIMER = "5000";
		
	const DEFAULT_BUTTON_WEIGHT = "93";
	const SAVED_COUNT = "SAVED_COUNT";
	
	//constructor
    public function DD_Delicious() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = "<div class='delicious-normal-img'><img src='" . DD_PLUGIN_URL . "image/delicious.png' alt='Delicious' /><div class='delicious-normal-text' id='DD_DELICIOUS_AJAX_POST_ID'>SAVED_COUNT</div></div>";
		$this->compactButtonWH = "<div class='delicious-compact-img'><img src='" . DD_PLUGIN_URL . "image/delicious-compact.png' alt='Delicious' /></div><span id='DD_DELICIOUS_AJAX_POST_ID'>SAVED_COUNT</span>";
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
       
    }  

	//override the base method to construct the source 
	public function construstURL($url,$title,$button, $postId){
	
    	//if lazy load, let jQuery handle it
    	if($this->get_lazy_load()==''){

    		$result = '';
			$count = '';
		
    		$shareUrl = urlencode($url);
			$deliciousStats = json_decode(file_get_contents('http://feeds.delicious.com/v2/json/urlinfo/data?url='.$shareUrl));
			
			if(!empty($deliciousStats)){
				if($deliciousStats[0]->total_posts == 0) {
				    $count = 'Save';
				} elseif($deliciousStats[0]->total_posts == 1) {
				    $count = '1 save';
				} else {
				    $count = $deliciousStats[0]->total_posts.' saves';
				}
			}else{
				$count = 'Save';
			}
			
	    	$result = str_replace(parent::VOTE_URL,$url,$this->baseURL);
    		$result = str_replace(self::VOTE_TITLE,$title,$result);
    		$result = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$result);
	    	$result = str_replace(self::SAVED_COUNT,$count,$result);
	    	$this->finalURL = $result;
	    	
    	}else{
   
	    	//$finalURL_lazy
	    	$finalURL_lazy = '';
	    	
	    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
	    		$finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL_lazy);
	    	}else{
	    		$finalURL_lazy = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL_lazy);
	    	}
	    	
	    	$finalURL_lazy = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy);
	    	$finalURL_lazy = str_replace(parent::VOTE_URL,$url,$finalURL_lazy);
	    	$finalURL_lazy = str_replace(parent::POST_ID,$postId,$finalURL_lazy);
	    	$finalURL_lazy = str_replace(self::SAVED_COUNT,'',$finalURL_lazy);
	    	
	    	$this->finalURL_lazy = $finalURL_lazy;
	    	
	    	//$finalURL_lazy_script
	    	$finalURL_lazy_script = '';
	    	if($this->get_ajax_left_float()=='' || $this->get_ajax_left_float()=='false'){
	    		$finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN,$this->getButtonDesign($button),$this->baseURL_lazy_script);
	    	}else{
	    		$finalURL_lazy_script = str_replace(parent::VOTE_BUTTON_DESIGN,$this->normalButtonWH,$this->baseURL_lazy_script);
	    	}
	    	$finalURL_lazy_script = str_replace(parent::VOTE_TITLE,$title,$finalURL_lazy_script);
	    	$finalURL_lazy_script = str_replace(parent::VOTE_URL,$url,$finalURL_lazy_script);
	    	$finalURL_lazy_script = str_replace(parent::POST_ID,$postId,$finalURL_lazy_script);
	    	
	    	$this->finalURL_lazy_script = $finalURL_lazy_script;
	    	
	    	//$final_scheduler_lazy_script
	    	$final_scheduler_lazy_script = '';
	    	$final_scheduler_lazy_script = str_replace(parent::SCHEDULER_TIMER,$this->scheduler_lazy_timer,$this->scheduler_lazy_script);
	    	$final_scheduler_lazy_script = str_replace(parent::POST_ID,$postId,$final_scheduler_lazy_script);
	    	
	    	$this->final_scheduler_lazy_script =  $final_scheduler_lazy_script;
	    	
    	}
		
    }
    
}

//sphinn.com properties and methods
class DD_Sphinn extends BaseDD{
	
	//constant value
	const NAME = "Sphinn";
	const BASEURL ="<script type='text/javascript'> submit_url = 'VOTE_URL'; </script> <script type='text/javascript' src='http://sphinn.com/evb/button.php'></script>";
	
	const OPTION_APPEND_TYPE = "dd_sphinn_appendType";
	const OPTION_BUTTON_DESIGN = "dd_sphinn_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_sphinn_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_sphinn_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_sphinn_lazy_load";
	
	const BASEURL_LAZY = "<div class='dd-sphinn-ajax-load dd-sphinn-POST_ID'></div><iframe class='DD_SPHINN_AJAX_POST_ID' width='0' height='0' scrolling='no' frameborder='0' src='#'></iframe>";
	const BASEURL_LAZY_SCRIPT = " function loadSphinn_POST_ID(){ jQuery(document).ready(function(\$) { \$('.dd-sphinn-POST_ID').remove();\$('.DD_SPHINN_AJAX_POST_ID').attr('width','54');\$('.DD_SPHINN_AJAX_POST_ID').attr('height','71');\$('.DD_SPHINN_AJAX_POST_ID').attr('src','http://sphinn.com/evb/url.php?url=VOTE_URL'); }); }";
	const SCHEDULER_LAZY_SCRIPT = "window.setTimeout('loadSphinn_POST_ID()',SCHEDULER_TIMER);";
	const SCHEDULER_LAZY_TIMER = "5000";
	
	const NORMAL_BUTTON_WH = "large";
	const COMPACT_BUTTON_WH = "small";
	const DEFAULT_BUTTON_WEIGHT = "92";
	
	const BUTTON_DROPDOWN_BOX_VALUE = "Normal";
	
	//constructor
    public function DD_Sphinn() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->baseURL_lazy = self::BASEURL_LAZY;
    	$this->baseURL_lazy_script = self::BASEURL_LAZY_SCRIPT;
    	$this->scheduler_lazy_script = self::SCHEDULER_LAZY_SCRIPT;
    	$this->scheduler_lazy_timer = self::SCHEDULER_LAZY_TIMER;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
        $this->button_dropdown_box_value = self::BUTTON_DROPDOWN_BOX_VALUE;
        
    } 
    
}

//stumbleupon.com properties and methods
class DD_StumbleUpon extends BaseDD{
	
	//constant value
	const NAME = "Stumbleupon";
	const BASEURL = "<script src='http://www.stumbleupon.com/hostedbadge.php?s=VOTE_BUTTON_DESIGN&amp;r=VOTE_URL'></script>";
	
	const OPTION_APPEND_TYPE = "dd_stumbleupon_appendType";
	const OPTION_BUTTON_DESIGN = "dd_stumbleupon_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_stumbleupon_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_stumbleupon_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_stumbleupon_lazy_load";
	
	const NORMAL_BUTTON_WH = "5";
	const COMPACT_BUTTON_WH = "1";
	const DEFAULT_BUTTON_WEIGHT = "91";
	
	//constructor
    public function DD_StumbleUpon() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    }     
}

//buzz.yahoo.com properties and methods
class DD_YBuzz extends BaseDD{
	
	//constant value
	const NAME = "YBuzz";
	const BASEURL = "<script type='text/javascript'>yahooBuzzArticleHeadline=VOTE_TITLE;yahooBuzzArticleId=VOTE_URL;</script><script type='text/javascript' src='http://d.yimg.com/ds/badge2.js' badgetype='VOTE_BUTTON_DESIGN'></script>";
	
	const OPTION_APPEND_TYPE = "dd_ybuzz_appendType";
	const OPTION_BUTTON_DESIGN = "dd_ybuzz_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_ybuzz_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_ybuzz_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_ybuzz_lazy_load";
	
	const NORMAL_BUTTON_WH = "square";
	const COMPACT_BUTTON_WH = "small-votes";
	const DEFAULT_BUTTON_WEIGHT = "90";
	
	      
	//constructor
    public function DD_YBuzz() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
    	
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    } 
    
}


//polladium.com properties and methods
class DD_Polladium extends BaseDD{
	
	//constant value
	const NAME = "Polladium";
	const BASEURL = "<script type='text/javascript' src='http://www.polladium.com/web_services/poll-this/poll-this.js?t=VOTE_TITLE&amp;u=VOTE_URL&amp;type=VOTE_BUTTON_DESIGN'></script>";
	
	const OPTION_APPEND_TYPE = "dd_polladium_appendType";
	const OPTION_BUTTON_DESIGN = "dd_polladium_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_polladium_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_polladium_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_polladium_lazy_load";
	
	const NORMAL_BUTTON_WH = "normal";
	const COMPACT_BUTTON_WH = "compact";
	const DEFAULT_BUTTON_WEIGHT = "89";
	
	//constructor
    public function DD_Polladium() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    }     
}

//post comments properties and methods
class DD_Comments extends BaseDD{
	
	//#comments
	//constant value
	const NAME = "Comments";
	const BASEURL = "<div id='dd_comments'><a class='clcount' href=VOTE_URL><span class='ctotal'>COMMENTS_COUNT</span><br /><span class='cmsg'>Comments</span></a><a class='clink' href=VOTE_URL></a></div>";
	
	const OPTION_APPEND_TYPE = "dd_comments_appendType";
	const OPTION_BUTTON_DESIGN = "dd_comments_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_comments_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_comments_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_comments_lazy_load";
	
	const DEFAULT_BUTTON_WEIGHT = "88";
	
	const COMMENTS_COUNT = "COMMENTS_COUNT";
	const COMMENTS_FLOW = "COMMENTS_FLOW";
	const COMMENTS_DETAIL_ID = "#comments";
	const COMMENTS_RESPONSE_ID = "#respond";
	
	const BUTTON_DROPDOWN_BOX_VALUE = "Normal";
	
	//constructor
    public function DD_Comments() {
    	
    	$normalbutton = "";
		
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = $normalbutton;
		$this->compactButtonWH = $normalbutton;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
        $this->button_dropdown_box_value = self::BUTTON_DROPDOWN_BOX_VALUE;
         
    }     
    
	//override the base method to construct the source 
	public function construstURL($url,$count){
    	$result = '';
    	
    	if($count!='0'){
    		$url = $url . self::COMMENTS_DETAIL_ID;
    	}else{
    		$url = $url . self::COMMENTS_RESPONSE_ID;
    	}
    	
    	$result = str_replace(self::VOTE_URL,$url,$this->baseURL);
    	$result = str_replace(self::COMMENTS_COUNT,$count,$result);
    	
    	$this->finalURL = $result;
    }
    
}


//designbump.com properties and methods
class DD_DesignBump extends BaseDD{
	
	//constant value
	const NAME = "DesignBump";
	const BASEURL = "<script type='text/javascript'>url_site='VOTE_URL'; </script> <script src='http://designbump.com/sites/all/modules/drigg_external/js/button.js' type='text/javascript'></script>";
	
	const OPTION_APPEND_TYPE = "dd_designbump_appendType";
	const OPTION_BUTTON_DESIGN = "dd_designbump_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_designbump_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_designbump_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_designbump_lazy_load";
	
	const NORMAL_BUTTON_WH = "";
	const COMPACT_BUTTON_WH = "";
	const DEFAULT_BUTTON_WEIGHT = "87";
	
	const BUTTON_DROPDOWN_BOX_VALUE = "Normal";
	
	//constructor
    public function DD_DesignBump() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
        $this->button_dropdown_box_value = self::BUTTON_DROPDOWN_BOX_VALUE;
         
    } 
    
}

//designfloat.com properties and methods
class DD_DesignFloat extends BaseDD{

	//constant value
	const NAME = "DesignFloat";	
	const BASEURL = "<script type='text/javascript'>submit_url = 'VOTE_URL';</script><script type='text/javascript' src='http://www.designfloat.com/VOTE_BUTTON_DESIGN/button.php'></script>";
	
	const OPTION_APPEND_TYPE = "dd_designfloat_appendType";
	const OPTION_BUTTON_DESIGN = "dd_designfloat_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_designfloat_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_designfloat_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_designfloat_lazy_load";
	
	const NORMAL_BUTTON_WH = "evb2";
	const COMPACT_BUTTON_WH = "evb";
	const DEFAULT_BUTTON_WEIGHT = "86";
	
	//constructor
    public function DD_DesignFloat() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    } 
    
}

//thewebblend.com properties and methods
class DD_WebBlend extends BaseDD{

	//constant value
	const NAME = "TheWebBlend";	
	const BASEURL = "<script type='text/javascript'>url_site='VOTE_URL';</script><script src='http://thewebblend.com/sites/all/modules/drigg_external/js/button.js' type='text/javascript'></script>";
	
	const OPTION_APPEND_TYPE = "dd_webblend_appendType";
	const OPTION_BUTTON_DESIGN = "dd_webblend_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_webblend_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_webblend_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_webblend_lazy_load";
	
	const NORMAL_BUTTON_WH = "";
	const COMPACT_BUTTON_WH = "";
	const DEFAULT_BUTTON_WEIGHT = "85";
	
	const BUTTON_DROPDOWN_BOX_VALUE = "Normal";
	
	//constructor
    public function DD_WebBlend() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
        
        $this->button_dropdown_box_value = self::BUTTON_DROPDOWN_BOX_VALUE;
    } 
    
}

//blogengage.com properties and methods
class DD_BlogEngage extends BaseDD{

	//constant value
	const NAME = "BogEngage";	
	const BASEURL = "<script type='text/javascript'>submit_url = 'VOTE_URL';</script><script src='http://blogengage.com/evb/VOTE_BUTTON_DESIGN'></script>";
  
	const OPTION_APPEND_TYPE = "dd_blogengage_appendType";
	const OPTION_BUTTON_DESIGN = "dd_blogengage_buttonDesign";
	const OPTION_BUTTON_WEIGHT = "dd_blogengage_button_weight";
	const OPTION_AJAX_LEFT_FLOAT = "dd_blogengage_ajax_left_float";
	const OPTION_LAZY_LOAD = "dd_blogengage_lazy_load";
	
	const NORMAL_BUTTON_WH = "button4.php";
	const COMPACT_BUTTON_WH = "button2.php";
	const DEFAULT_BUTTON_WEIGHT = "84";
	
	//constructor
    public function DD_BlogEngage() {
    	
    	//wordpress option value
		$this->option_append_type = self::OPTION_APPEND_TYPE;
		$this->option_button_design = self::OPTION_BUTTON_DESIGN;
		$this->option_button_weight = self::OPTION_BUTTON_WEIGHT;
		$this->option_ajax_left_float = self::OPTION_AJAX_LEFT_FLOAT;
		$this->option_lazy_load = self::OPTION_LAZY_LOAD;
		
		$this->normalButtonWH = self::NORMAL_BUTTON_WH;
		$this->compactButtonWH = self::COMPACT_BUTTON_WH;
		$this->button_weight_value = self::DEFAULT_BUTTON_WEIGHT;
		
        parent::BaseDD(self::NAME, self::BASEURL);
    } 
    
}  
?>