/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, url, height, width) {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $(document.body)
      .append("<div id='GB_overlay'></div><div id='GB_window'>"
        + "<div class='btn'>close</div></div>");
    $("#GB_window .btn").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position);
    GB_DONE = true;
  }

  $("#GB_frame").remove();
  $("#GB_window").append("<iframe id='GB_frame' name='newsday_greybox' src='"+url+"' frameBorder='0' scrolling='no' allowtransparency='1'></iframe>");

  $("#GB_caption").html(caption);
  $("#GB_overlay").show();
  GB_position();

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
}

function GB_hide() {
  $("#GB_window,#GB_overlay").hide();
}

function GB_position() {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
  $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
    left: ((w - GB_WIDTH)/2)+"px" });
  $("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
}

function GB_notGoAway() {
	  $("#GB_window,#GB_overlay").show();  
	}
		
	function GB_updateAccountWindow() {
	  $("#GB_window  .btn").hide();
	  $("#GB_overlay").click(GB_notGoAway);
	  var GB_HEIGHT = 250;
	  var GB_WIDTH = 800;
	  var de = document.documentElement;
	  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	  $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
	    left: ((w - GB_WIDTH)/2)+"px" });
	  $("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
	}
	

	function GB_updateAccountWindowCl() {
	  //closes box then reloads page to complete login
      $("#GB_window .btn").click(function(){
            window.parent.document.location.reload(true); });
            
      $("#GB_overlay").click(GB_notGoAway);
      var GB_HEIGHT = 250;
      var GB_WIDTH = 800;
      var de = document.documentElement;
      var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
      $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
        left: ((w - GB_WIDTH)/2)+"px" });
      $("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
    }
	
	
/* Cues for Greybox here */
var GB_ANIMATION = true;
/*
      $(document).ready(function(){
        $("a.emailLink").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,440,500);
          return false;
        });
      });
 */     
    
      $(document).ready(function(){
        $("a.rateArticle").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,150,400);
          return false;
        });
      });
      
    
      $(document).ready(function(){
        $("a.loginBox").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,410,425);
          return false;
        });
      });
      
      $(document).ready(function(){
        $("a.resetPassword").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,450,450);
          return false;
        });
		
      });
      
      $(document).ready(function(){
        $("a.mapExpand").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,440,640);
          return false;
        });
      });
      
       $(document).ready(function(){
        $("a.oolBox").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,350,425);
          return false;
        });
      });
      
      $(document).ready(function(){
        $("a.socMedia").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,350,425);
          return false;
        });
      });
      
      $(document).ready(function(){
        $(".photoPop").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,490,680);
          return false;
        });
      });
      $(document).ready(function(){
          $("a.favorites").click(function(){
            var t = this.title || this.innerHTML || this.href;
            GB_show(t,this.href,350,425);
            return false;
          });
        });
      /* UGC input Greybox */
      $(document).ready(function(){
          $("a.newstip").click(function(){
            var t = this.title || this.innerHTML || this.href;
            GB_show(t,this.href,536,420);
            return false;
          });
        });      
      $(document).ready(function(){
        $("a.mediaSubmit").click(function(){
          var t = this.title || this.innerHTML || this.href;
          GB_show(t,this.href,450,670);
          return false;
        });
      });    
      $(document).ready(function(){
          $("a.postAComment").click(function(){
            var t = this.title || this.innerHTML || this.href;
            GB_show(t,this.href,400,425);
            return false;
          });
        });
      
      /* unclosable Greybox script */
      var close = false;
      var _HEIGHT;
      var _WIDTH;

     function unclosableGB_show(url, height, width) {
      _HEIGHT = height;
      _WIDTH = width;
      if(!close) {
          $(document.body).append("<div id='GB_overlay'></div><div id='GB_window'>" + "<div class='goBack'><a href='javascript:window.parent.history.go(-1);'>go back</a></div>" + "</div>");
          $(window).resize(unclosableGB_position);
          close = true;
      }
      $("#GB_frame").remove();
      $("#GB_window").append("<iframe id='GB_frame' name='newsday_greybox' frameBorder='0' scrolling='no' allowtransparency='1' src='"+url+"'></iframe>");
      $("#GB_overlay").show();
      unclosableGB_position();
     }

     function unclosableGB_position() {
      var de = document.documentElement;
      var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
      $("#GB_window").css({width:_WIDTH+"px",height:_HEIGHT+"px",left: ((w - _WIDTH)/2)+"px" });
      $("#GB_frame").css("height",_HEIGHT - 32 +"px");
     }
     /* end of unclosable Greybox script */      
      
