// JavaScript Document
var link="http://emailmebutton.com/";
var type,emailme_id,typeofbutton,emailme_formid,buttontop,buttonbottom,textcolor,text;
if(typeofbutton!=undefined)
{
// new button code
var buttoncode="<button type=\"button\" class=\"emailmebutton\" style=\"font-family: 'Lucida Sans Unicode', Helvetica, Arial, sans-serif; font-weight: 500;font-size: 22px;padding: 10px 15px;border-radius: 5px;-moz-border-radius: 5px;-webkit-border-radius: 5px;text-decoration:none;background:"+buttontop+";background:-webkit-gradient(linear, right top, right bottom,from("+buttontop+"),to("+buttonbottom+")); border:1px solid "+buttonbottom+"; color:"+textcolor+";\">"+text+"</button>";	

//alert('newbutton');
if(typeofbutton=='float')
{
//code for floating
//document.getElementById("emailme_div1").innerHTML="<div style='width: 125px;position: fixed; bottom: 0;right: 0;height:30px;z-index: 1000;'><a class='emailme_link' href='"+link+"index.php/frame/view/"+emailme_formid+"' border='0'><img src='http://emailmebutton.com/images/emailme.png' class='emailme_link2' onMouseOut='this.style.opacity=1' onMouseOver='this.style.opacity=0.9' border='0'/></a></div>";
	
document.getElementById("emailme_div1").innerHTML="<div style='position: fixed; bottom: 0;right: 0;height:40px;z-index: 1000;'><a class='emailme_link' href='"+link+"index.php/frame/view/"+emailme_formid+"' border='0'>"+buttoncode+"</a></div>";	

}
else if(typeofbutton=='fixed')
{
//code for fixed	-- same as buttoncode withut enclosing div

document.getElementById("emailme_div1").innerHTML="<a class='emailme_link' href='"+link+"index.php/frame/view/"+emailme_formid+"' border='0'>"+buttoncode+"</a>";	

}

}
else
{
// old code	
}
(function() {

// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/

if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.6.1') {
    var script_tag = document.createElement('script');
    script_tag.setAttribute("type","text/javascript");
    script_tag.setAttribute("src",
        "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js");
    script_tag.onload = scriptLoadHandler;

	 script_tag.onreadystatechange = function () { // Same thing but for IE
	
        if (this.readyState == 'complete' || this.readyState == 'loaded') {
            
			//load for IE
		//	var head= document.getElementsByTagName('head')[0];
		//	   var script= document.createElement('script');
		//	   script.type= 'text/javascript';
		//	   script.src= link+"javascripts/jquery.colorbox-min.js";
		//	   head.appendChild(script); 
			
			scriptLoadHandler();
        }
    };
   	

	// Try to find the head, otherwise default to the documentElement
 (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
    // The jQuery version on the window is the one we want to use
    jQuery = window.jQuery;
    main();
}

/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
	
	//load css first
	
	$("head").append("<link>");
	css = $("head").children(":last");
	css.attr({
	      rel:  "stylesheet",
	      type: "text/css",
	      href: link+"stylesheets/colorbox.css" 
	    });
	
	//load colorbox js
	
	$.getScript(link+"javascripts/jquery.colorbox-min.js", function(data, textStatus){
	   
	//if(textStatus=="success")
	{
		 jQuery = window.jQuery.noConflict();
		main();
	}
	//console.log(data); //data returned
	   //console.log(textStatus); //success
	   //console.log('Load was performed.');
	});
	
    // Restore $ and window.jQuery to their previous values and store the
    // new jQuery in our local jQuery variable
	//		var script_tag2 = document.createElement('script');
    //script_tag2.setAttribute("type","text/javascript");
    //script_tag2.setAttribute("src",link+"javascripts/jquery.colorbox-min.js");
//alert(link+"javascripts/jquery.colorbox-min.js");
	//document.getElementsByTagName("head")[0].appendChild(script_tag2);
		
   
    // Call our main function
    
	
	
	
	//main(); 
}


function main() { 

 

    jQuery(document).ready(function($) { 
		
		//For Hover Changes for all browsers except IE
		if (!$.browser.msie) {
		
		$('.emailmebutton').hover(function(){
					$('.emailmebutton').css('background', buttontop);
		},
		function(){
				$('.emailmebutton').css('background', buttontop);
				$('.emailmebutton').css('background', '-webkit-gradient(linear, right top, right bottom,from('+buttontop+'),to('+buttonbottom+'))');
				$('.emailmebutton').css('background', '-moz-linear-gradient(top,'+buttontop+' 0%,'+buttonbottom+' 90%)');
		});
		
	} // browser detect IE
		
		//For colorbox method
		$(".emailme_link").colorbox({width:"550px",height:"590px", iframe:true});
		
		//For Tracking
		//Tracking on every refresh
			$.ajax( {
				type: "POST",
				url: link+"index.php/tracking",
				data: "dname="+document.domain,
			});
		
    });
}

})(); 
