﻿//I <3 Cufon!
Cufon.replace('#cta_RFP .widgetCTA .widgetCTADescription, #rotatingCTA .widgetCTA .widgetCTADescription, #loginCtaArea1 .widgetCTADescription, #loginCtaArea2 .widgetCTADescription', { hover: true, fontFamily: 'Trebuchet MS' });
Cufon.replace('#cta_RFP .widgetCTA h1, #rotatingCTA .widgetCTA h1, .homepage #ctaShell h1, #loginCtaArea1 h1, #loginCtaArea2 h1', { hover: true, fontFamily: 'Trebuchet MS', textShadow: '1px 1px #818181', color: '-linear-gradient(#e5e5e5, 0.4=#fff, 1=#fff, rgb(0, 0, 0))' });
//Cufon.replace('#h-nav>ul>li>a', { hover: true, fontFamily: 'Trebuchet MS' });

//IE fix for html5
// html5shiv MIT @rem remysharp.com/html5-enabling-script
// iepp v1.5.1 MIT @jon_neal iecss.com/print-protector
/*@cc_on(function(p,e){var q=e.createElement("div");q.innerHTML="<z>i</z>";q.childNodes.length!==1&&function(){function r(a,b){if(g[a])g[a].styleSheet.cssText+=b;else{var c=s[l],d=e[j]("style");d.media=a;c.insertBefore(d,c[l]);g[a]=d;r(a,b)}}function t(a,b){for(var c=new RegExp("\\b("+m+")\\b(?!.*[;}])","gi"),d=function(k){return".iepp_"+k},h=-1;++h<a.length;){b=a[h].media||b;t(a[h].imports,b);r(b,a[h].cssText.replace(c,d))}}for(var s=e.documentElement,i=e.createDocumentFragment(),g={},m="abbr article aside audio canvas details figcaption figure footer header hgroup mark meter nav output progress section summary time video".replace(/ /g, '|'),
n=m.split("|"),f=[],o=-1,l="firstChild",j="createElement";++o<n.length;){e[j](n[o]);i[j](n[o])}i=i.appendChild(e[j]("div"));p.attachEvent("onbeforeprint",function(){for(var a,b=e.getElementsByTagName("*"),c,d,h=new RegExp("^"+m+"$","i"),k=-1;++k<b.length;)if((a=b[k])&&(d=a.nodeName.match(h))){c=new RegExp("^\\s*<"+d+"(.*)\\/"+d+">\\s*$","i");i.innerHTML=a.outerHTML.replace(/\r|\n/g," ").replace(c,a.currentStyle.display=="block"?"<div$1/div>":"<span$1/span>");c=i.childNodes[0];c.className+=" iepp_"+
d;c=f[f.length]=[a,c];a.parentNode.replaceChild(c[1],c[0])}t(e.styleSheets,"all")});p.attachEvent("onafterprint",function(){for(var a=-1,b;++a<f.length;)f[a][1].parentNode.replaceChild(f[a][0],f[a][1]);for(b in g)s[l].removeChild(g[b]);g={};f=[]})}()})(this,document);@*/


$(function(){

     //depending on the parent found in the breadcrumbs, clone the related nav into the left subnav
     //p.s. I totally could'be just used .current. i'm an idiot.
     //with that being said, this is being commented out.
     /*$("body:not(.homepage) #h-nav>ul>li>a").each(function(){
          var thisNavItem = $(this).html();
          if ( $("#breadcrumbs li:nth-child(2) a").length )
               { var currentParent = $("#breadcrumbs li:nth-child(2) a").html(); }
               else { var currentParent = $("#breadcrumbs li:nth-child(2)").html(); } 
          var currentParent = $("#h-nav>ul>li.current>a");
          
          //press articles don't have real parents, so let's pretend they're part of press room.
          if ( currentParent == null ) { var currentParent = "Press Room"; }
          
          //if ( thisNavItem == currentParent )
               { $(this).parent().clone().appendTo("#leftSubNavigation #subTop"); }
               
     }); */
     
     var currentParent = $("#h-nav>ul>li.current");
     if ( currentParent == null ) { alert("im null"); }
     $(currentParent).clone().appendTo("#leftSubNavigation #subTop");
     
     var currentParent = $("#h-nav>ul>li.current>a").html();
     if ( currentParent == null ) { var currentParent = "Press Room"; }
     var currentParent = currentParent.replace(/ /g,'');
     $("body:not(.homepage)").addClass(currentParent); 
    
    //title-ize the main LI 
    var subNavTitle = $("#subTop>li>a").html();
    $("#subTop h1").append(subNavTitle);
    $("#subTop>li>ul").appendTo("#subTop");
    $("#subTop>li").remove(); 
    
    //cycle right-hand CTAs outside of dev mode
    if ( $("#toolbarContainer").length ) { $("#rotatingCTA").css({"height" : "auto"}); }
         else { $("#rotatingCTA").after('<div id="paginator">').cycle({
              fx: 'fade', 
              speed:  'fast', 
              timeout: 5000, 
              pager:  '#paginator' 
         }); }
         
    //cycle the login CTAs
    if ( $("#toolbarContainer").length ) { $("#loginCtaArea1").css({"height" : "auto"}); }
         else {$("#loginCycle").cycle({
              fx: 'fade', 
              speed:  '1000', 
              timeout: 5000, 
              pager:  '#loginPaginator' 
         }); }
    
    //round the header image
    $.fn.corner.defaults.useNative = false;
    $("#imgHolder").corner("10px");
    
    //round the nav
    $.fn.corner.defaults.useNative = true;
    //$("#h-nav ul li.current").corner("5px top");
    
    //round pagination links
    $("#paginator a").corner("4px"); 
    
    //emulate the div tag soup found on the original site.
    $("#h-nav>ul>li>ul").addClass("subMenus").wrap("<div class='uberShell'><div class='subMenuShell'></div></div>");
    
    //in dev mode, show all the "related materials" items.
    if ( $("#toolbarContainer").length ) {  $("#r-subnavigation .widgetCTA").show();   }
   
   //the "related materials" items change based on the parent page.
   //this script searches the description field for "tags".
   //depending on what tags are found, 
   //the item will show on the related parent page and all its children.
   $("#r-subTop .widgetCTADescription").each(function(){
   
        var relSolutions = "solutions";
        var relCompany = "company";
        var relPress = "press";
        var relResource = "resource";
        var ctaDescription = $(this).text();
        //i should learn switches...
        if ( ctaDescription.indexOf(relSolutions)!=-1 )
             { $(this).parent().parent().addClass("relSolutions"); }
             else { /*do nothing*/ }
        if ( ctaDescription.indexOf(relCompany)!=-1 )
             { $(this).parent().parent().addClass("relCompany"); }
             else { /*do nothing*/ }    
        if ( ctaDescription.indexOf(relPress)!=-1 )
             { $(this).parent().parent().addClass("relPressRoom"); }
             else { /*do nothing*/ }       
        if ( ctaDescription.indexOf(relResource)!=-1 )
             { $(this).parent().parent().addClass("relResource"); }
             else { /*do nothing*/ }        
    });
     
    //on homepage, copy the rotating cta (the one on the right in the subpages) to the homepageCTA div.
    $("body.homepage #rotatingCTA").appendTo("#homeCTA");
    $("body.homepage #paginator").appendTo("#homeCTA");
      if ( $("body.homepage").length ) {
         if ( $("#toolbarContainer").length ) { $("#rotatingCTA").replaceWith("<p style='color: red'>Update CTAs from within a subpage</p>"); }
    }
    
    //add classes to phone/fax
    $("#address .tel:first").addClass("regPhone");
    $("#address .tel:last").addClass("daFax");
    
    //initialize the socialbookmarks from the original site.
    $("div#widgetSocialBookmarks2380").SocialBookmarks({target:"_blank"});
    
    //div toggles
    $("#divtoggles li:nth-child(1)").click(function(){
         $(".toggleContainer>div").hide(); $(".toggleContainer>div:nth-child(1)").show(); $("#divtoggles li a").removeClass("classon"); $("a", this).addClass("classon");});
    
    $("#divtoggles li:nth-child(2)").click(function(){
         $(".toggleContainer>div").hide(); $(".toggleContainer>div:nth-child(2)").show(); $("#divtoggles li a").removeClass("classon"); $("a", this).addClass("classon");});
         
     //make a cool 'external' selector. exceptions: mailto: and javscript jazz
     $.expr[':'].external = function(obj){return !obj.href.match(/^mailto\:/)
     && !obj.href.match(/^javascript/) && !obj.href.match(/^http\:\/\/www.vizergy.com/) && (obj.hostname != location.hostname);};
     
     //add the class "external", and add popup.
     $("#col2 a:external:not(.shadowbox), a[href*=.pdf], a[href*=.doc], a[href*=.docx]").addClass("external").click(function(){window.open(this.href); return false;;})
     
     //add another class for specific file types
     $("a[href*=.pdf]").addClass("pdf");
     $("a[href*=.doc], a[href*=.docx]").addClass("doc");   
     
     //v-site gallery organization
     if ( $("#toolbarContainer").length ) { /*do nothing, and leave it ugly. otherwise, we can't edit this junk. */ }
          else {
               $("#liveVsites .widgetCTA").each(function(){
               
                    var templateTitle = $(this).find("h1").text().replace(/ /g,'');
                    var divContainer = templateTitle + "Container";
                    
                    if ( $("div#" + divContainer).length ) { /*do nothing */ }
                         else { $("#liveVsites").append("<div id='" + divContainer +"' class='templateContainer'><div class='templateTitle'></div><div class='templateThumbContainer'></div><div class='colorOptions'></div></div>"); }
                    
                    if ( templateTitle == divContainer.replace(/Container/g,'') ) 
                         { $(this).appendTo("div#" + divContainer + " .colorOptions"); }
                    
               
               });
               $("#staticVsites .widgetCTA").each(function(){
               
                    var templateTitle = $(this).find("h1").text().replace(/ /g,'');
                    var divContainer = templateTitle + "Container";
                    
                    if ( $("div#" + divContainer).length ) { /*do nothing */ }
                         else { $("#staticVsites").append("<div id='" + divContainer +"' class='templateContainer'><div class='templateTitle'></div><div class='templateThumbContainer'></div><div class='colorOptions'></div></div>"); }
                    
                    if ( templateTitle == divContainer.replace(/Container/g,'') ) 
                         { $(this).appendTo("div#" + divContainer + " .colorOptions"); }
                    
                    
               
               }); 
               $("#brandedVsites .widgetCTA").each(function(){
               
                    var templateTitle = $(this).find("h1").text().replace(/ /g,'');
                    var divContainer = templateTitle + "Container";
                    
                    if ( $("div#" + divContainer).length ) { /*do nothing */ }
                         else { $("#brandedVsites").append("<div id='" + divContainer +"' class='templateContainer'><div class='templateTitle'></div><div class='templateThumbContainer'></div><div class='colorOptions'></div></div>"); }
                    
                    if ( templateTitle == divContainer.replace(/Container/g,'') ) 
                         { $(this).appendTo("div#" + divContainer + " .colorOptions"); }
                    
                    
               
               }); 
               }//end else
     
     //let's reorganize. I want all the h1's in a container
     $(".templateContainer .widgetCTA h1").each(function(){
         var titleContainer = $(this).parent().parent().parent().parent().find(".templateTitle");
         $(this).appendTo(titleContainer);
     });
     
     //all the images in another container
     $(".templateContainer .widgetCTA .widgetCTAimg").each(function(){
         var thumbContainer = $(this).parent().parent().parent().parent().find(".templateThumbContainer");
         $(this).appendTo(thumbContainer);
     });
     
     //add classes to the a's for the colors.
     $(".colorOptions a span").each(function(){
          var theColor = $(this).text();
          $(this).parent().parent().addClass(theColor + "Temp");     
     });
     
     //the static v-sites, need to be shadowboxed.
     //the filename should always be templatename_colorvariant_large.jpg
     $("#staticVsites .colorOptions a").each(function(){
     
          var templateTitle = $(this).parent().parent().parent().find(".templateTitle>h1:first").text();
          var templateColor = $(this).find("span").text();
          $(this)
          .attr( 'href', 'files/394/' + templateTitle + '_' + templateColor + '_large.jpg' )
          .attr('title', templateTitle + " - " + templateColor)
          .attr('rel', 'shadowbox[' + templateTitle + ']');
     
     });
     
     //the branded v-sites, need to be shadowboxed.
     //the filename should always be templatename_large.jpg
     $("#brandedVsites .colorOptions a").each(function(){
     
          var templateTitle = $(this).parent().parent().parent().find(".templateTitle>h1:first").text();
          var templateTitleNoSpace = templateTitle.replace(/ /g,'');
          var templateColor = $(this).find("span").text();
          $(this)
          .attr( 'href', 'files/394/' + templateTitleNoSpace + '_large.jpg' )
          .attr('title', templateTitle)
          .attr('rel', 'shadowbox[' + templateTitle + ']');
     
     });
     
     //stick the training calendar in a shadowbox.
     $("#widgetCTA28903").find("a").attr("rel", "shadowbox");
     
     //re-initialize shadowbox
     Shadowbox.setup();
     
     //remove vizergy from footer. replace with logo.
     $(".org").replaceWith("<img src='files/templates/199/new-viz-logo-sm.gif' class='org'>");
   
     //fix cufon's issue with not realizing that it's out of its hover state.
     $('#h-nav>ul>li').hover(
          function(){ /* do nothing */ },
          function(){ Cufon.refresh("#h-nav>ul>li>a"); }
     );   
      
       
});