﻿

// facebook appid = 187502661308500

window.fbAsyncInit = function() {
	FB.init({appId: '187502661308500', status: true, cookie: true, xfbml: true});
	FB.getLoginStatus(fbLoginStatus);
	FB.Event.subscribe('auth.statusChange', fbLoginStatus);
	FB.Event.subscribe('edge.create', function(href, widget) {likeEvent();});

};


(function() {
	var e = document.createElement('script');
	e.type = 'text/javascript';
	e.src = document.location.protocol + '//connect.facebook.net/ko_KR/all.js';
	e.async = true;
	document.getElementById('fb-root').appendChild(e);
}());

   
function likeEvent() {
//	window.location.reload();

	//var auth_login = document.getElementById('facebookAuthLogin');
	//var auth_logout = document.getElementById('facebookAuthLogout');

	//FB.getLoginStatus(fbLoginStatus);
//	FB.getLoginStatus(function(response) {
//		if (response.session) {
//			alert('aaaa');
//		} else {
//			alert('bbb');
//		}
//    });
}


// Facebook login Check.
function fbLoginStatus(response) {
	var auth_login = document.getElementById('facebookAuthLogin');
	var auth_logout = document.getElementById('facebookAuthLogout');
	var ExpDate = new Date();
	ExpDate.setTime(ExpDate.getTime() + 1000*60*60*24*365);
	
	if (response.session) {
		SetCookie("f_login", "Yes", ExpDate);
		auth_login.style.display = "none";
		auth_logout.style.display = "";
		auth_logout.onclick = function() {
			FB.logout(function(response) {});
		};
	} else {
		SetCookie("f_login", "No", ExpDate);
		auth_login.style.display = "";
		auth_logout.style.display = "none";
		auth_login.onclick = function() {
			facebookLogin();
//			FB.login(function(response) {
//				if (response.session) {
//				} else {
//				}
//			},{perms:'email,user_photos,read_stream,publish_stream,create_event,rsvp_event,sms,offline_access'});
		};
	}
}


function facebookShare(id, title, image){
	var url = 'http://www.facebook.com/sharer/sharer.php?';
	url = url + 'u='+ encodeURIComponent('http://www.theshopon.com/product/'+ id +'?view=facebook');
	
    var width = 590;
    var height = 400;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open(url,"share_facebook","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=0,resizable=0");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}



function twitterShare(id, title){
	var url = encodeURIComponent('http://www.theshopon.com/product/'+ id);
	var text = '[SHOPON] '+ encodeURI(title);
	
    var width = 550;
    var height = 450;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open('https://twitter.com/share?url='+ url +'&text='+ text +'&via=theSHOPON',"share_twitter","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=1,resizable=1");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}    


function smsShare(url) {

    var width = 590;
    var height = 460;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open(url,"share_sms","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=0,resizable=0");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}  



function openLikeIt(url) {
    var width = 550;
    var height = 300;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open(url,"shopon_likeit","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=0,resizable=0");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}


function facebookLogin(){
	var url = 'https://www.facebook.com/dialog/oauth?client_id=187502661308500&display=popup&redirect_uri=http://www.theshopon.com/facebook/check.do&scope=email,user_photos,read_stream,publish_stream,sms,offline_access,status_update';
	
    window.name = "shopon_main";
    
    var width = 640;
    var height = 300;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open(url,"facebook_login","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=0,resizable=0");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}

function facebookCheckPop(url) {
    var width = 640;
    var height = 300;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;

    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open(url,"facebook_check","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=0,resizable=0");
    if (win != null) {
    	win.focus();
    } else {
    	alert('차단된 팝업창을 허용해 주십시오.');
    }    
}


function twitterInvite(uuid){
	var url = encodeURIComponent('http://www.theshopon.com/'+ uuid);
	var text = '[SHOPON] - Social Communication is love.';
	
    var width = 550;
    var height = 450;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open('https://twitter.com/share?url='+ url +'&text='+ text,"share_twitter","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=1,resizable=1");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}   


function facebookInvite(uuid) {
	
	var url = 'http://www.facebook.com/sharer/sharer.php?';
	url = url + 'u='+ encodeURIComponent('http://www.theshopon.com/'+ uuid);
	
    var width = 590;
    var height = 400;
    var c = screen.height;
    var b = screen.width;
    var left = Math.round((b/2)-(width/2));
    var top = 0;
    var Y = $(this).attr('href');
    if (c > height) {
    	top = Math.round((c/2)-(height/2));
    }
    var win = window.open(url,"share_invite","left="+ left +",top="+ top +",width="+ width +",height="+ height +",personalbar=0,toolbar=0,scrollbars=0,resizable=0");
    if (win) {
    	win.focus();
    } else {
    	window.location.href = Y;
    }
}


