﻿/* mooSocialize - bookmark tool ©2008 artViper designstudio - all rights reserved */
/* information about this tool and other widgets: info@artviper.net  */

window.addEvent('domready',function(){
	$$('.socializer').addEvent('click',function(){
		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;
		var div 	= new Element('div');
		var imgloc  = "/images/socializer/";
		div.setStyle('top',pos);
		div.setStyle('left',left);
		div.addClass('soc_container');
		div.setAttribute('id','containerx');
		div.injectInside(document.body);
		
		$(div).addEvent('click',function(){
			this.dispose();
		})
		
		$(div).addEvent('blur',function(){
			this.dispose();
		})
		
		
		// close button
		var closeme = new Element('img');
		closeme.src=imgloc+"close.gif";
		closeme.setAttribute('id','close');
		closeme.injectInside(div);
		closeme.addEvent('click',function(){
			div.dispose();
		})
		
		var title= this.title;
		var url  = this.alt;
	
		var name = new Element('h1');
		name.innerHTML = '<img src="'+imgloc+'socializer.png" width="300" height="25" />';
		name.injectInside(div);
		
		var left = new Element('div');
		left.addClass('soc_left');
		left.injectInside(div);
		
		// facebook.com
		var img = new Element('img');
		img.alt = 'send to digg';
		img.src = imgloc+'facebook.gif';
		img.injectInside(left);
		
		var myLink = new Element('a');
		myLink.href  = 'http://www.facebook.com/sharer.php?u='+url+'&t='+title;
		myLink.title = 'send to facebook';
		myLink.innerHTML = 'facebook';
		myLink.injectInside(left);
		
		// linkedin.com
		var img = new Element('img');
		img.alt = 'send to digg';
		img.src = imgloc+'linkedin.gif';
		img.injectInside(left);
		
		var myLink = new Element('a');
		myLink.href  = 'http://www.linkedin.com/shareArticle?mini=true&url='+url+'&title='+title;
		myLink.title = 'send to linkedin';
		myLink.innerHTML = 'linkedin';
		myLink.injectInside(left);
		
		// digg.com
		var img = new Element('img');
		img.alt = 'send to digg';
		img.src = imgloc+'digg.png';
		img.injectInside(left);
		
		var myLink = new Element('a');
		myLink.href  = 'http://digg.com/submit?phase=2&url='+url+'&title='+title;
		myLink.title = 'send to del.icio.us';
		myLink.innerHTML = 'digg';
		myLink.injectInside(left);
		
		// put in right side container	
		var right = new Element('div');
		right.addClass('soc_left');
		right.injectInside(div);
		
		// yahoo.com
		var img = new Element('img');
		img.alt = 'send to yahoo.com';
		img.src = imgloc+'im_yahoo.gif';
		img.injectInside(right);
		
		var myLink = new Element('a');
		myLink.href  = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+url+'&t='+title
		myLink.title = 'send to yahoo';
		myLink.innerHTML = 'yahoo';
		myLink.injectInside(right);
		
		// myspace
		var img = new Element('img');
		img.alt = 'send to myspace';
		img.src = imgloc+'myspace.gif';
		img.injectInside(right);
		
		var myLink = new Element('a');
		myLink.href  = 'http://www.myspace.com/index.cfm?fuseaction=postto&u='+url+'&t='+title;
		myLink.title = 'send to myspace';
		myLink.innerHTML = 'myspace';
		myLink.injectInside(right);
		
		// yahoo.com
		var img = new Element('img');
		img.alt = 'send to mixx';
		img.src = imgloc+'mixx.gif';
		img.injectInside(right);
		
		var myLink = new Element('a');
		myLink.href  = 'http://mini.mixx.com/submit/story?page_url='+url+'&title='+title;
		myLink.title = 'send to mixx';
		myLink.innerHTML = 'mixx';
		myLink.injectInside(right);
		
		// fade in
		// 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]
				  });
		
		// 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 - 780) /2;
			var wind 		= new Element('div', {
				styles: {
						'top':scTop+20,
						'opacity':'0.99',
						'width':'780px',
						'left':left + 'px',
						'position':'absolute'						
					    }
				})
				
			wind.addClass('open_window');		
			
			var closeX = new Element('img');
			closeX.src = imgloc+"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{
		$('containerx').effect('opacity', { duration:300, wait:true, transition:Fx.Transitions.linear}).start(1,0);
		$('containerx').dispose();
		}
	})
})
