/* mooSocialize - bookmark tool ©2008 artViper designstudio - all rights reserved */
/* information about this tool and other widgets: info@artviper.net  */
/* the header 'artViper's social bookmark widget has not to be disposed */
/* same goes for the link to this tool */

window.addEvent('domready',function(){

	$$('.socializer').addEvent('click',function(e){
		if(document.getElementById('containerx') == null){
		
	
		// define container pos
		var top 	= this.getCoordinates().top.toInt();
		var height	= this.getCoordinates().height.toInt();
		var left	= this.getCoordinates().left.toInt();
		var pos 	= top+height+0;
		var div 	= new Element('div');
		div.setStyle('top',pos);
		div.setStyle('left',left);
		div.addClass('soc_container');
		div.setAttribute('id','containerx');
		div.injectInside(document.body);
				
		$(div).addEvent('blur',function(){
			this.dispose();
		})
		
		// close button
		var closeme = new Element('img');
		closeme.src="http://belizespecials.nplhost.com/js/moosochalie/images/close.gif";
		closeme.setAttribute('id','close');
		closeme.injectInside(div);
		closeme.addEvent('click',function(){
			div.dispose();
		})
		
		var title= this.title;
		var url  = encodeURIComponent(this.rel);
		var left = new Element('div');
		left.addClass('soc_left');
		left.injectInside(div);
/*************
 * I C O N S *
 *************/

		// del.icio.us
		var img = new Element('img');
		img.alt = 'send to del.icio.us';
		img.src = 'http://belizespecials.nplhost.com/js/moosochalie/images/delicious.png';
		img.injectInside(left);
		
		var myLink = new Element('a');
		myLink.href  = 'http://del.icio.us/post?url='+url+'&title='+title;
		myLink.title = 'send to del.icio.us';
		myLink.innerHTML = 'Del.icio.us';
		myLink.injectInside(left);
		
		// Twitta
		var img = new Element('img');
		img.alt = 'send to Twitter';
		img.src = 'http://belizespecials.nplhost.com/js/moosochalie/images/twitter.gif';
		img.injectInside(left);
		var myLink = new Element('a');
		myLink.href = 'http://twitter.com/home?status=' + url;
		myLink.innerHTML = 'Twitter';
		myLink.injectInside(left);

		// digg.com
		var img = new Element('img');
		img.alt = 'send to digg';
		img.src = 'http://belizespecials.nplhost.com/js/moosochalie/images/digg.png';
		img.injectInside(left);
		
		var myLink = new Element('a');
		myLink.href  = 'http://digg.com/remote-submit?phase=2&title='+title+'&url='+url;
		myLink.title = 'Post this story to Digg';
		myLink.innerHTML = 'Digg';
		myLink.injectInside(left);


		// stumbleupon.com

		var img = new Element('img');
		img.alt = 'send to stumbleupon';
		img.src = 'http://belizespecials.nplhost.com/js/moosochalie/images/stumbleupon.png';
		img.injectInside(left);
		
		var myLink = new Element('a');
		myLink.href  = 'http://www.stumbleupon.com/submit?url='+url+'&title='+title;
		myLink.title = 'send to stumbleupon';
		myLink.innerHTML = 'StumbleUpon';
		myLink.injectInside(left);


                // facebook.com
                                                                                                                                                                                   
                var img = new Element('img');
                img.alt = 'send to Facebook';
                img.src = 'http://www.belizetourism.org/moosochalie/images/facebook.gif';
                img.injectInside(left);
                                                                                                                                                                                   
                var myLink = new Element('a');
                                                                                                                                                                                   
                var tmp = 'http://www.facebook.com/sharer.php?u=' + url + '&t=' + title;
                myLink.href = tmp;
                myLink.title = 'send to Facebook';
                myLink.innerHTML = 'Facebook';
                myLink.injectInside(left);
/*************
 * S N O C I *
 ************/
		// fade in
		var eff = new Fx.Morph(div, { duration: 500, wait:true, transition:Fx.Transitions.linear }).chain(function(){
																											 $$('.soc_left').setStyle('visibility','visible');	});
														
		
		eff.start({
				  	'opacity':[0,1]
				  });
		
				
		
	//	div.effect('opacity',{duration:500, wait:true, transition:Fx.Transitions.linear }).chain(function(){
			
	//	}).start(0,1);	
		
		
		
		// open new window via ajax
		$$('.soc_left a').addEvent('click',function(e){
			e = new Event(e).stop();
			
			var address 	= this.href;
			var scTop 		= window.getScrollTop().toInt();
			
			// is it a crap IE ?
			nav = navigator.appName;
	
			if(nav.indexOf('Microsoft') != -1){
				if(navigator.appVersion.indexOf('MSIE 6') != -1 || navigator.appVersion.indexOf('MSIE 7') != -1){
				var	width = document.body.clientWidth;
				}									
				
			}else{
				var	width	= window.innerWidth.toInt();
			}
			
			var left		= (width - 580) /2;
			var wind 		= new Element('div', {
				styles: {
						'top':scTop+120,
						'opacity':'0.9',
						'width':'580px',
						'left':left + 'px',
						'position':'absolute'						
					    }
				})
				
			wind.addClass('open_window');		
			
			var closeX = new Element('img');
			closeX.src = "http://belizespecials.nplhost.com/js/moosochalie/images/close.gif";
			closeX.addClass('close');
			closeX.addEvent('click',function(){
				wind.dispose();
			})
			
			closeX.injectInside(wind);
			var c	 = new Element('iframe');			
			c.src	 = address;	
			c.setStyle('width','780px');
			c.setStyle('height','500px');
			c.setStyle('border','none');
			c.setStyle('margin','0 auto');
			c.injectInside(wind);
			wind.injectInside(document.body);
		})
	  }else{
		var eff = new Fx.Morph('containerx', { duration: 500, wait:true, transition:Fx.Transitions.linear }).chain(function(){
				$('containerx').dispose();
																															});														
		
		eff.start({
				  	'opacity':[0,1]
				  });
		
		
		}
	})
})

