var idp = null;
$(document).ready(function() {
	$(".connectWrapper img.idpico").click(
		function(){ 
			idp = $( this ).attr( "rel" );

			switch( idp ){
				case "google": 
				case "twitter": 
				case "yahoo": 
				case "facebook": 
				case "aol": 
				case "vimeo": 
				case "myspace": 
				case "tumblr": 
				case "lastfm": 
				case "twitter": 
				case "linkedin": 
					start_auth("?provider=" + idp);
				break; 

				case "wordpress" : case "blogger" : case "flickr" :  case "livejournal" :  
								if( idp == "blogger" ){
									$("#openidm").html( "Please enter your blog name" );
								}
								else{
									$("#openidm").html( "Please enter your username" );
								}
								$("#openidun").css( "width", "220" );
								$("#openidimg").attr( "src", "images/icons/" + idp + ".png" );
								$("#idps").hide();
								$("#openidid").show();  
								break;
				case "openid" : 
								$("#openidm").html( "Please enter your OpenID URL" );
								$("#openidun").css( "width", "350" );
								$("#openidimg").attr( "src", "images/icons/" + idp + ".png" );
								$("#idps").hide();
								$("#openidid").show();  
								break;

				default: alert( "u no fun" );
			}
		}
	); 

	$("#openidbtn").click(
		function(){
			oi = un = $( "#openidun" ).val();

			if( ! un ){
				alert( "nah not like that! put your username or blog name on this input field." );
				
				return false;
			}

			switch( idp ){ 
				case "wordpress" : oi = "http://" + un + ".wordpress.com"; break;
				case "livejournal" : oi = "http://" + un + ".livejournal.com"; break;
				case "blogger" : oi = "http://" + un + ".blogspot.com"; break;
				case "flickr" : oi = "http://www.flickr.com/photos/" + un + "/"; break;   
			}
			
			start_auth("?provider=OpenID&openid_identifier=" + escape( oi ) ); 
		}
	);  

	$("#backtolist").click(
		function(){
			$("#idps").show();
			$("#openidid").hide();

			return false;
		}
	);
});
function start_auth( params ) {
	start_url = params + "&_ts=" + (new Date()).getTime();
	window.open(
		start_url, 
		"hybridauth_social_sing_on", 
		"location=0,status=0,scrollbars=0,width=800,height=500"
	);  
}
