var shortUrl = "";

whenDOMReady(function(){ 
    getShortUrl();
});

function getShortUrl(){
    var domain = window.location.host;
	var url =  'http://' + domain + '/getShortUrl.do';
	var imagingurl = encodeURIComponent(window.location);
	var param = 'longUrl=' + imagingurl;  
	new nv.Ajax(url, param, callback_shortening, 'GET', 'JSON');
}

function callback_shortening(resultObj){
	if ( resultObj.status_code == "200" ) {
		shortUrl = resultObj.data.url;
	}
}	

function sharingOpen(type) {
	var imagingurl = encodeURIComponent(window.location);
	var title = encodeURIComponent(nv.$('hidden.title').value);
	var openUrl = "";
	var srcurl = encodeURIComponent("http://www.samsungimaging.com");
	var srctitle = encodeURIComponent("SAMSUNG IMAGING");
	
	var andStr = "&";
	if(navigator.appName.indexOf("Microsoft") > 0) {
		andStr = "&amp;";
	}

	if ( type == "twitter" )
		openUrl = "http://twitter.com/home?status="+ title + "+-" + shortUrl; 
	if ( type == "digg" )
		openUrl = "http://digg.com/submit?phase=2"+andStr+"url="+imagingurl+andStr+"title="+title;
	if ( type == "delicious" )
		openUrl = "http://del.icio.us/post?url="+imagingurl+andStr+"title="+title;
	if ( type == "technorati" )
		openUrl = "http://technorati.com/faves?add="+imagingurl;
	if ( type == "stumbleupon" )
		openUrl = "http://www.stumbleupon.com/submit?url="+imagingurl+andStr+"title="+title;
	if ( type == "facebook" )
		openUrl = "http://www.facebook.com/share.php?v=4"+andStr+"src=bm"+andStr+"u="+imagingurl+andStr+"t="+title;
	if ( type == "myspace" )
		openUrl = "http://www.myspace.com/Modules/PostTo/Pages/?u="+imagingurl+andStr+"t="+title;
	if ( type == "reddit" )
		openUrl = "http://reddit.com/submit?url="+imagingurl+andStr+"title="+title;
	if ( type == "mailto" )
	{
		document.charset="euc-kr";
		openUrl = "mailto:?subject="+nv.$('hidden.title').value+andStr+"body="+imagingurl;
	}
	if ( type == "mixx" )
		openUrl = "http://www.mixx.com/submit?page_url="+imagingurl+andStr+"title="+title;
	if ( type == "newsvine" )
		openUrl = "http://www.newsvine.com/_tools/seed"+andStr+"save?u="+imagingurl+andStr+"h="+title;
	if ( type == "yahoobuzz" )
		openUrl = "http://buzz.yahoo.com/buzz?targetUrl="+imagingurl;
	if ( type == "googlebuzz" )
		openUrl = "http://www.google.com/reader/link?url="+imagingurl+"&title="+title+"&srcURL=http://www.samsungimaging.co.kr&srcTitle=SAMSUNGIMAGING";
	if ( type == "linkedin" )
		openUrl = "http://www.linkedin.com/shareArticle?mini=true&url="+imagingurl+"&title="+title+"&summary="+srcurl+"&source="+srctitle;
	if ( type == "me2day" )
		openUrl = "http://me2day.net/posts/new?new_post[body]="+title+" "+imagingurl+"&new_post[tags]="+srcurl+" "+srctitle;
	if ( type == "daumyozm")
		openUrl = "http://yozm.daum.net/api/popup/post?prefix="+title+"&link="+imagingurl;
	

	window.open( openUrl );
	document.charset="UTF-8";
}
