var MSG_EMAIL = "Please specify a valid email address.";
var MSG_MESSAGE = "Please enter your message.";
var MSG_SOURCE = "Please upload your design sources or specify a link to your file(s).";
var NAME_EMAIL = "email";
var NAME_EMAIL_LOGIN = "_input_email";
var NAME_TEXT = "text";
var NAME_TICKETTEXT = "_input_text";
var NAME_TIMEOFFSET = "_input_gmt";
var NAME_LINK = "_input_attachment_link";
var NAME_HEX = "_hex";
var NAME_SOURCE = "_input_source";
var NAME_SOURCELINK = "_input_source_link";
function initCookies(){
    var A = new String(document.referrer);
    A = (A.indexOf(document.location.host) != -1) ? "<direct>" : document.referrer;
    if (!getCookie("ref1")) {
        setCookie("ref1", A);
        setCookie("ref2", "<first access>")
    }
    else {
        if (A != "local") {
            setCookie("ref2", A)
        }
    }
}

function setCookie(B, C){
    var A = new Date();
    A = new Date(A.getFullYear(), A.getMonth() + 1, A.getDate());
    document.cookie = B + "=" + escape(C) + "; expires=" + A.toGMTString()
}

function getCookie(A){
    var D = document.cookie.split("; ");
    for (var C = 0; C < D.length; C++) {
        var B = D[C].split("=");
        if (A == B[0]) {
            return unescape(B[1])
        }
    }
    return null
}

function initLinksTarget(){
    $("a[rel='nofollow']").attr('target', '_blank');
    //$$("a[rel=nofollow]").each(function(A){
      //  A.setProperty("target", "_blank")
    //})
}

function initExamplePage(){
    $('ul.images a').click(function(){
        var Atx = $(this).attr("rel");
        var A =  Atx.replace("#", "");        
        window.open("http://www.htmlcut.com/resources/viewer.html#" + A, "Example", "width=1050,height=650,toolbar=no,status=no,scrollbars=yes,menubar=no,resizable=yes");
        return false
    });
    //$$("ul.images a").addEvent("click", function(){
      //  var A = this.getProperty("rel").replace("#", "");
//        window.open("http://www.htmlcut.com/resources/viewer.html#" + A, "Example", "width=1050,height=650,toolbar=no,status=no,scrollbars=yes,menubar=no,resizable=yes");
  //      return false
    //})
}

function initLiveSupport(){
    $('a.chat-link').click(function(){
      chatPopup = window.open(this.attr('href'), "CHAT", "width=620,height=572,toolbar=no,status=no,scrollbars=no,menubar=no,resizable=no");
      if (chatPopup) {            
         chatPopup.focus()
      }
        return false
    });
    //$$("a.chat-link").addEvent("click", function(A){
      //  chatPopup = window.open(this.href, "CHAT", "width=620,height=572,toolbar=no,status=no,scrollbars=no,menubar=no,resizable=no");
        
    //})
}

function initMcAfeeSecure(){
/*    var A = $("mcafeesecure");
    if (A) {
        A.addEvent("contextmenu", function(){
            alert("Copying Prohibited by Law - McAfee Secure is a Trademark of McAfee, Inc.");
            return false
        })
    }*/
}

function initTrustGuard(){
    /*var A = $("trust-guard");
    if (A) {
        A.addEvent("click", function(){
            var B = navigator.appName != "Microsoft Internet Explorer" ? "yes" : "no";
            window.open(this.href, "welcome", "location=" + B + ",scrollbars=yes,width=517,height=" + screen.availHeight + ",menubar=no,toolbar=no");
            return false
        })
    }*/
}

function initRibbon(){
/*    var A = $("ribbon");
    if (A) {
        window.addEvent("resize", function(){
            ribbonReposition()
        })
    }*/
}

function ribbonReposition(){
    var C = $("ribbon");
    if (C) {
        var A = getPageSize();
        var B = getSizew();
        if (B.x < 1130) {
            C.addClass("hidden")
        }
        else {
            C.removeClass("hidden")
        }
    }
}

function myobject() {
  this.x = 0;
  this.y = 0;
}

function getSizew() {
	var size = new myobject();
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  size.x = myWidth;
  size.y = myHeight;
	return size;
}

function setTimeOffset(C){
    var E = C.elements[NAME_TIMEOFFSET];
    if (E) {
        var G = new Date();
        var A = new Date(G.getFullYear(), 0, 1);
        var F = new Date(G.getFullYear(), 6, 1);
        var D = -A.getTimezoneOffset();
        var B = -F.getTimezoneOffset();
        E.value = (D < B) ? D : B
    }
}

function isEmail(B){
    var A = B.trim().toLowerCase();
    var C = /^[a-zA-Z0-9\._\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
    return C.test(B)
}

function _isEmail(C){
    var B = C.trim().toLowerCase();
    var D = /^[a-zA-Z0-9\._\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$/;
    var A = /^cno\:\d*$/;
    return D.test(C) || A.test(C)
}

function sizeToKB(A){
    var B = "B";
    if ((A / 1048576) > 1) {
        B = "MB";
        A /= 1048576
    }
    else {
        if ((A / 1024) > 1) {
            B = "kB";
            A /= 1024
        }
    }
    return A.round(1) + " " + B
}

function getPageScroll(){
    var A;
    if (self.pageYOffset) {
        A = self.pageYOffset
    }
    else {
        if (document.documentElement && document.documentElement.scrollTop) {
            A = document.documentElement.scrollTop
        }
        else {
            if (document.body) {
                A = document.body.scrollTop
            }
        }
    }
    return A
}

function getPageSize(){
    var C, A;
    if (window.innerHeight && window.scrollMaxY) {
        C = document.body.scrollWidth;
        A = window.innerHeight + window.scrollMaxY
    }
    else {
        if (document.body.scrollHeight > document.body.offsetHeight) {
            C = document.body.scrollWidth;
            A = document.body.scrollHeight
        }
        else {
            C = document.body.offsetWidth;
            A = document.body.offsetHeight
        }
    }
    var B, D;
    if (self.innerHeight) {
        B = self.innerWidth;
        D = self.innerHeight
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            B = document.documentElement.clientWidth;
            D = document.documentElement.clientHeight
        }
        else {
            if (document.body) {
                B = document.body.clientWidth;
                D = document.body.clientHeight
            }
        }
    }
    if (A < D) {
        pageHeight = D
    }
    else {
        pageHeight = A
    }
    if (C < B) {
        pageWidth = B
    }
    else {
        pageWidth = C
    }
    return new Array(pageWidth, pageHeight, B, D)
}

function initPage(){
    initCookies();
    initLinksTarget();
    initExamplePage();
    initLiveSupport();
    initMcAfeeSecure();
    initTrustGuard();
    initRibbon();
    ribbonReposition();
    initOurVideoPopup()
}

function detectSafariVersion(){
    if (navigator.appVersion.indexOf("Safari") != -1) {
        if (!window.getComputedStyle) {
            document.body.className += " safari2"
        }
        else {
            document.body.className += " safari3"
        }
    }
}

function detectBrowser(){
    var A = function(){
        var B = navigator.userAgent.toLowerCase(), D = function(F, G){
            if (!F.className) {
                F.className = G
            }
            else {
                var E = F.className;
                E += (" " + G);
                F.className = E
            }
        }, C = function(E){
            return (B.indexOf(E) != -1)
        };
        D(document.getElementsByTagName("html")[0], [(!(/opera|webtv/i.test(B)) && /msie (\d)/.test(B)) ? ("ie ie" + RegExp.$1) : C("firefox/2") ? "gecko ff2" : C("firefox/3") ? "gecko ff3" : C("gecko/index.html") ? "gecko" : C("chrome/index.html") ? "chrome" : C("opera/9") ? "opera opera9" : /opera (\d)/.test(B) ? "opera opera" + RegExp.$1 : C("konqueror") ? "konqueror" : C("applewebkit/index.html") ? "webkit safari" : C("mozilla/index.html") ? "gecko" : "", (C("x11") || C("linux")) ? " linux" : C("mac") ? " mac" : C("win") ? " win" : ""].join(" "))
    }()
}

$(document).ready(function(){
    initPage();
    detectBrowser();
    detectSafariVersion();						   
						   });

var _IE = (navigator.appName.indexOf("Microsoft Internet Explorer") != -1) ? true : false;
function initOurVideoPopup(){
    var A = $("video-shadow");
    var G = false;
    var C = $("our-video-button");
    if (!A) {
        A = document.createElement("div");
        A.id = "video-shadow";
        document.body.appendChild(A);
        A = $(A)
    }
    if (C) {
        var D = C.hash;
        if (D && D != "#") {
            D = $(D.substr(1))
        }
        else {
            D = false
        }
        if (D) {
            if (_IE) {
                var F = D.getElement("div.html");
                var B = F.innerHTML;
                F.innerHTML = ""
            }
            C.onclick = function(){
                pageTracker._trackEvent("video", "view", "P2H in our own words");
                E();
                return false
            };
            D.getElement("a.our-video-close").onclick = function(){
                G = false;
                D.style.display = "none";
                A.style.display = "none";
                if (_IE) {
                    F.innerHTML = ""
                }
                return false
            };
            A.onclick = function(){
                G = false;
                D.style.display = "none";
                A.style.display = "none";
                if (_IE) {
                    F.innerHTML = ""
                }
                return false
            }
        }
    }
    function E(){
        G = true;
        if (_IE) {
            F.innerHTML = B
        }
        A.style.height = getPageSize()[1] + "px";
        A.style.display = "block";
        D.style.display = "block"
    }
};
