/* Requires jquery.js */
/* Requires jquery.blockui.js */

//jQuery(document).ready(function(){
//jQuery('#metaNav li a').eq(0).click(function() {
//	    
//		showFlyover('<h1>Flyover</h1><h5><a href="#">Close</a></h5>');
//	});
//	/*jQuery('p a').click(function(){
//		showFlyover('<h1>Flyover</h1><h5><a href="#">Close</a></h5>');
//	});*/
//	
//});

//function showFlyover(html){
//	jQuery.blockUI({ message:html, css:{cursor:'auto'} });
//	jQuery('.blockMsg a').click(function(){
//		jQuery.unblockUI();
//	});
//}


/* Requires jquery.js */

jQuery(document).ready(function() {
    jQuery('#lnk_mergeAcct').click(function() {
        return doFlip(this, '#flipBod_merge');
    });

    jQuery('#lnk_prevMerge').click(function() {
        return doFlip(this, '#flipBod_associate');
    });

    jQuery('#fbFly_terminate .flyclose').click(function() {

        parent.window.location.reload();
    });

    jQuery('#fbFly_assoc .flyclose').click(function() {

        jQuery('#fbFly_terminate').show();
        jQuery('#fbFly_assoc').hide();
    });

    jQuery('.returnPrevious').click(function() {

        jQuery('#fbFly_terminate').hide();
        jQuery('#fbFly_assoc').show();
    });

    jQuery("#input_assocOpt_new_email").focus();
    
});

function doFlip(org, target) {
    var flipSet = jQuery(org).parents('.flipSet');

    jQuery('.curr', flipSet).removeClass('curr');
    jQuery(target, flipSet).addClass('curr');

    return false;
}


var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    close: function() {
        jQuery(".modal-window").remove();
        //jQuery(".modal-overlay").remove();
        location.reload();
    },
    open: function() {
        var modal = "";
        //modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
        modal += "<div class=\"loadingMsg\"><h3>Loading, please wait</h3></div>";
        modal += this.content;
        //modal += "</div>";

        jQuery(this.parent).append(modal);

        jQuery(".modal-window").append("<a class=\"close-window\"></a>");
        jQuery(".close-window").click(function() { modalWindow.close(); });
        //jQuery(".modal-overlay").click(function() { modalWindow.close(); });
        //jQuery(".flyclose").click(function() { modalWindow.close(); });
    }
};


var openMyModal = function(source) {
    modalWindow.windowId = "myModal";
    modalWindow.width = 615;
    modalWindow.height = 500;
    modalWindow.content = "<iframe width='615' height='500' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'></iframe>";
    modalWindow.open();
};

         //window.onload = function() {
//

          //          if (FB_ConnectFlag == "1")
           //         {
           //           FB_RequireFeatures(["XFBML"], function() {
            //                FB.Facebook.init(api, "/xd_receiver.html");
            //            });
            //        }
             //   }


function fbSignIN() {    
    FB_RequireFeatures(["Connect"], function() {
        FB.Facebook.init(api, "/xd_receiver.htm", null);

        FB.Connect.requireSession();
        var tempRurl = '/tFBSignIn.html';

        FB.Facebook.get_sessionState().waitUntilReady(function() {
            openMyModal(tempRurl);
            posLoadingMsg();
        })
    })
}
             
              function onConnected() {

                      if (getCookie('INFO')) {
                          //alert(getCookie('ID'));
    
                          parent.window.location.reload();
                      }
                      else {

                          //document.getElementById('flip').style.display = 'block';
                          openMyModal('/tFBSignIn.html');
                          return false;
                      }
                  //}
              }

              function onNotConnected() {

                  FB.Connect.requireSession();
              }


              function getCookie(c_name) {
                  if (document.cookie.length > 0) {
                      c_start = document.cookie.indexOf(c_name + "=");
                      if (c_start != -1) {
                          c_start = c_start + c_name.length + 1;
                          c_end = document.cookie.indexOf(";", c_start);
                          if (c_end == -1) c_end = document.cookie.length;
                          return unescape(document.cookie.substring(c_start, c_end));
                      }
                  }
                  return "";
              }

              function logout() {
                  FB_RequireFeatures(["XFBML"], function() {
                      FB.Facebook.init(api, "/xd_receiver.htm");

                      FB.Connect.logout(function() {

                          jQuery.ajax({
                              type: 'GET',
                              async: false,
                              url: '/logout.php',
                              success: function() {
                                window.location.href = '/';
                              },
                              error: function() { window.location.href = '/'; }
                          });


                      });

                  });

              }


              function logoutFB() {
                  FB_RequireFeatures(["XFBML"], function() {
                      FB.Facebook.init(api, "/xd_receiver.htm");

                      FB.Connect.logout(function() {

                          //                          window.location.href = '/';
                          //                          if (jQuery.browser.msie) {
                          //                              window.location.href = '/';
                          //                          }
                          //                          else {
                          //                              window.location.reload();
                          //                          }

                          parent.window.location.reload();
                      });


                  });

              }


              function logoutFBZagat() {
                  FB_RequireFeatures(["XFBML"], function() {
                      FB.Facebook.init(api, "/xd_receiver.htm");

                      FB.Connect.logout(function() {

                      jQuery.ajax({
                          type: 'GET',
                          async: false,
                          url: '/Account/SignOut.aspx',
                          success: function() {
                          parent.window.location.reload();
                          },
                          error: function() { parent.window.location.reload(); }
                      });

                      });


                  });

              }

function posLoadingMsg() {
    var top = (jQuery('.loadingMsg').parent().height() / 2) - 32;
    var left = (jQuery('.loadingMsg').parent().width() / 2) - 32;

    jQuery('.loadingMsg').css('top', top+'px');
    jQuery('.loadingMsg').css('left', left+'px');   
}
