﻿//------- Settings--------------------------------------------------------//

//set your image directory path with a '/' on the end
var imageDirectory = "images/";
//specify the name of the shadow image
var imageShadow = "icons-shadow.png"
//use reverse drop? true : false 
var reverseDrop = true;
//set icon size either 32px, 24px or 16px
var iconSize = "24px";
//add the names of all images (comma seperated)
var images = new Array(
                "icon_facebook.png",
                "twitter.png"
            );
//add your bookmark icon functions here same amount as images
var iconfunctions = new Array(
                "openFacebookWindow();",    //facebook
                "openTwitterWindow()"
            );

//------ Variables -----------------------------------------------------//

//do not change these variables
var iconDropInterval;
var IntCount = 0;

//for reverse drop
var c = 1;
var img = images.length;
var currImg;

var u = location.href;
     
//--------- On load -------------------------------------------------------------------------------//

$(document).ready(function() {

    InitialiseIcons();
    //drop icons on load
    iconDropInterval = setInterval("dropIcons()", 50); //drop speed

    if (iconSize == "32px") {
        $('.bounce').mouseenter(function() {
            $(this).animate({ "top": "-=20px" }, 500);
            $(this).parent().parent().next().find('.shadow').animate({ height: "10px", width: "30px", left: "9px", top: "2px", opacity: 0.25 }, 500)
        });
        $('.bounce').mouseleave(function() {
            $(this).animate({ "top": "+=23px" }, 400);
            $(this).animate({ "top": "-=3px" }, 400);
            $(this).parent().parent().next().find('.shadow').animate({ height: "19px", width: "50px", left: "0px", top: "-1px", opacity: 0.75 }, 500)
        });
    } else if (iconSize == "24px") {
        $('.bounce').mouseenter(function() {
            $(this).animate({ "top": "-=15px" }, 500);
            $(this).parent().parent().next().find('.shadow').animate({ height: "8px", width: "20px", left: "7px", top: "2px", opacity: 0.25 }, 500)
        });
        $('.bounce').mouseleave(function() {
            $(this).animate({ "top": "+=18px" }, 400);
            $(this).animate({ "top": "-=3px" }, 400);
            $(this).parent().parent().next().find('.shadow').animate({ height: "12px", width: "37px", left: "0px", top: "-1px", opacity: 0.75 }, 500)
        });
    } else {
        $('.bounce').mouseenter(function() {
            $(this).animate({ "top": "-=10px" }, 500);
            $(this).parent().parent().next().find('.shadow').animate({ height: "5px", width: "15px", left: "5px", top: "2px", opacity: 0.25 }, 500)
        });
        $('.bounce').mouseleave(function() {
            $(this).animate({ "top": "+=13px" }, 400);
            $(this).animate({ "top": "-=3px" }, 400);
            $(this).parent().parent().next().find('.shadow').animate({ height: "8px", width: "25px", left: "0px", top: "0px", opacity: 0.75 }, 500)
        });
    }
});

//------------ run on setup -----------------------------------------------------------------------------//

function InitialiseIcons() {
   for(var i = 0; i <images.length; i++){
		var urlString;
		
		if(iconfunctions[i] == "facebook"){
			urlString = '<a href="javascript:return false;" name="fb_share" type="icon">' + '<img class="bounce" src="' + imageDirectory + images[i] + '"/>' + '</a>'
		}else{
			urlString = '<a href="javascript:' + iconfunctions[i] + '">' + '<img class="bounce" src="' + imageDirectory + images[i] + '"/>' + '</a>'
		}	
       $('#main_icon_wrap').append('<div class="icon_wrap" id="bcon' + i + '">'
                                            + '<div class="bounce-container">'
                                                + urlString
                                            + '</div>'
                                            + '<div class="shadow-container">'
                                                + '<img class="shadow" src="' + imageDirectory + imageShadow + '"/>'
                                            + '</div>'
                                       + '</div>').hide();
       if (iconSize == "32px") {
           $('.icon_wrap').css({ width: "45px", height: "45px" });
           $('.bounce-container').css({left: '9px', top: '6px' });
           $('.shadow-container').css({left: '0px', top: '46px'});
           $('.bounce').css({ width: iconSize, height: iconSize });
           $('.shadow').css({ height: "10px", width: "30px", left: "9px", top: "2px", opacity: 0.25 });
       } else if (iconSize == "24px") {
           $('.icon_wrap').css({ width: "34px", height: "34px" });
           $('.bounce-container').css({ left: '7px', top: '5px' });
           $('.shadow-container').css({ left: '0px', top: '35px' });
           $('.bounce').css({ width: iconSize, height: iconSize });
           $('.shadow').css({ height: "7px", width: "23px", left: "6px", top: "2px", opacity: 0.25 });
       } else {
           $('.icon_wrap').css({ width: "23px", height: "23px" });
           $('.bounce-container').css({ left: '4px', top: '3px' });
           $('.shadow-container').css({ left: '0px', top: '23px' });
           $('.bounce').css({ width: iconSize, height: iconSize });
           $('.shadow').css({ height: "5px", width: "15px", left: "5px", top: "2px", opacity: 0.25 });
       }
    }
};

function dropIcons() {
    if (IntCount < images.length) {
        currImg = img - c;
        var divid = "#bcon" + IntCount;
        
        if (reverseDrop == true) {
            divid = "#bcon" + currImg;
        }

        $('#main_icon_wrap').show();

        if (iconSize == "32px") {
            $('#main_icon_wrap').find('#' + divid).find('.bounce').animate({ "top": "+=23px" }, 300);
            $('#main_icon_wrap').find('#' + divid).find('.bounce').animate({ "top": "-=3px" }, 300);
            $('#main_icon_wrap').find('#' + divid).find('.bounce').parent().parent().next().find('.shadow').animate({ height: "19px", width: "50px", left: "0px", top: "-1px", opacity: 0.75 }, 300);
        } else if (iconSize == "24px") {
            $('#main_icon_wrap').find('#' + divid).find('.bounce').animate({ "top": "+=18px" }, 300);
            $('#main_icon_wrap').find('#' + divid).find('.bounce').animate({ "top": "-=3px" }, 300);
            $('#main_icon_wrap').find('#' + divid).find('.bounce').parent().parent().next().find('.shadow').animate({ height: "12px", width: "37px", left: "0px", top: "0px", opacity: 0.75 }, 300);
        } else {
            $('#main_icon_wrap').find('#' + divid).find('.bounce').animate({ "top": "+=11px" }, 300);
            $('#main_icon_wrap').find('#' + divid).find('.bounce').animate({ "top": "-=2px" }, 300);
            $('#main_icon_wrap').find('#' + divid).find('.bounce').parent().parent().next().find('.shadow').animate({ height: "8px", width: "25px", left: "0px", top: "0px", opacity: 0.75 }, 300);
        }
        IntCount++;
        c++; 
    } else {
        clearInterval(iconDropInterval);
    }
};

//---------- social bookmark functions-------------------------------------------------------------------//

function openFacebookWindow() {
   //$(this).attr("name", "fb_share");
    window.open('http://www.facebook.com/sharer.php?t=' + encodeURIComponent(document.title) + '&u=' + encodeURIComponent(u));
};

function openTwitterWindow() {
    var your_twitter_id = "twitterid";
    window.open('http://twitter.com/home?status=RT' + your_twitter_id + ':+' + encodeURIComponent(document.title)+ '+-+' + encodeURIComponent(u));
};
 
function openWordPressWindow() {
	
};


