// JavaScript Document
$(document).ready(function() {//start document ready function

//ADD FANCYBOX POPUPS 

$('#vip-competition-prize-details').click(function() {
	TINY.box.show($('.vip-competition .prize-details').html(), 0, 400, 0, 1);
	return false;
});

//SET TIMESTAMP IN FORM

    //$("#edit-uid").attr('value', $("#timestamp").text());
	//$("#edit-destination").attr('value', 'call-me-back-thank-you?UID='+$("#timestamp").text())


//OPEN BLOG LINK IN NEW WINDOW
$(function(){
    $('#block-aggregator-feed-1 a').click(function(){
        window.open(this.href);
        return false;
    });
});

$('ul.nice-menu-down li#menu-1731 ul ul').remove();


//GET A QUOTE
$('#edit-operatingsystem').change(function() {
  if($(this).val()=='Linux'){
	  $('#edit-linuxos-wrapper').show();
	  $('#edit-windowsos-wrapper').hide();
  }else if($(this).val()=='Windows'){
	  $('#edit-windowsos-wrapper').show();
	  $('#edit-linuxos-wrapper').hide();
  }
});



$('#at-a-glance ul').shuffle();
var numShown = 5; // Initial rows shown & index
 // Hide rows and add clickable div
$("#at-a-glance ul li:lt(5)").show();


$('div.vip.vip-program tr').each(function() {
	$(this).children('td:first').addClass('col1')
})



//js styling of the nice menu drop down menu
$('ul.nice-menu li.menuparent ul li.menuparent').each(function() {
	$(this).find('a:eq(0)').hover(function() {
		$(this).css({
	  		background: "#dfdfdf url('images/arrow_right.png') 143px 8px no-repeat" 
		});
	}, function() {
		$(this).css({
			background: "#fdfdfd" 
		});
	});
});

$('ul.nice-menu').children('li').each(function() {
	//maintain menu state
	
	
	if($(this).find('ul').length > 0) {
		var anchorBg = $(this).find('a:eq(0)').css('background');
		var $span = $('<span class="menuparent_level1_closure" />');
		$span.css({
			width: '3px',
			height: '28px',
			background: "url(images/menuparent_children_bg_left.jpg)",
			display: 'block',
			position: 'absolute',
			left: '0px',
			top: '0px'
		});
		
		$(this).hover(function() {
			$(this).find('a:first').css({
				background: '#f55e22 url(images/menuparent_children_bg_right.jpg) top right no-repeat'
			});
		
			//enable the rounded corners on the menu items with a span
			$(this).append($span);

		}, function() {
			$(this).find('a:eq(0)').css('background', 'transparent');
			$span.remove();
		});
	
	} else {
		var $span = $('<span class="menuparent_level1_nochildren_closure" />');
		$span.css({
			width: '3px',
			height: '36px',
			background: "url(images/menuparent_nochildren_bg_left.jpg)",
			display: 'block',
			position: 'absolute',
			left: '0px',
			top: '0px'
		});
		
		$(this).hover(function() {
			$(this).find('a:eq(0)').css({
				'padding-bottom': '0px',
				height: '27px',
				background: '#f55e22 url(images/menuparent_nochildren_bg_right.jpg) top right no-repeat'
			});
			$(this).css('position', 'relative').append($span);	
		}, function() {
			$(this).find('a:eq(0)').css('background', 'transparent');
			$span.remove();
		});
	}
});

$('ul.nice-menu ul').append(
	$('<li />').append('<img style="display: block;" src="images/menu_bottom_shadow.png"/>')
		.css({background: 'transparent', border: '0', display: 'block'}));




$('<span class="openpopup">Learn more</span>').appendTo('#node-1 p:first');
$('#node-1 p:first').show();
$('#node-1 #speech-bubble-text').wrapAll('<div class="homepagepopup" />');

$('<span class="openpopup">En savoir plus</span>').appendTo('#node-328 p:first');
$('#node-328 p:first').show();
$('#node-328 #speech-bubble-text').wrapAll('<div class="homepagepopup" />');


$('div.homepagepopup').prepend('<p class="closepopup">X</p>')
$('div.homepagepopup').appendTo('#homepagemidRight').hide();
var hmr = $('#homepagemidRight');
var overlayDiv = $('<div />')
                .css({
                    background: '#fff',
                    width: hmr.outerWidth() + 2,
                    height: hmr.outerHeight() + 2,
                    display: 'block',
                    position: 'absolute',
                    left: -1,
                    top: -1,
		    'z-index': 100
                })
                    .hide();
                hmr.append(overlayDiv);


            $('span.openpopup').click(function() {

                    overlayDiv.fadeIn(400);

                    $('div.homepagepopup').show().css('z-index', 1000);
            });
            $('p.closepopup').click(function() {
                    overlayDiv.fadeOut(250);
                    $('div.homepagepopup').hide();
            });



$('#readmore').toggle(
          function () {
            $('#node-1 p').fadeIn('fast');
                    $(this).text('Close...');
          },
          function () {
            $('#node-1 p:not(:first)').fadeOut('fast');
                    $(this).text('Read more...')
          }
);
					
					
					
//START OF SET BLOG HREF TARGET TO _BLANK	
	$('.block-aggregator a[href^="http://"]').attr("target", "_blank");	
//START OF SET BLOG HREF TARGET TO _BLANK	


	
//START OF CASE STUDY PAGINATION
	var paginationCS = "<ul id='pagCS'></ul>";
	$('.node-type-casestudy .node .content').append(paginationCS);
	var currentCS = window.location.pathname;
	
	
	if($("#menuPanel a[href=" + currentCS + "]").parent().next().length){;
	var nextCS = $("#menuPanel a[href=" + currentCS + "]").parent().next().html();
	$('#pagCS').append("<li class='pagnext'>"+nextCS+"</li>")
	};
	
	
	if($("#menuPanel a[href=" + currentCS + "]").parent().prev().length){;
	var prevCS = $("#menuPanel a[href=" + currentCS + "]").parent().prev().html();
	$('#pagCS').append("<li class='pagprev'>"+prevCS+"</li>")
	};
	
	
	
//END OF CASE STUDY PAGINATION
	

	
	


		
	$('ul#utilityMenu li.uSales').hover(
  function () {
    $('div#utilityMenuOver').slideDown('fast');
  }, 
  function () {
     $('div#utilityMenuOver').slideUp('fast');
  }
);

$('body').supersleight();
$('body').supersleight({shim: '../images/x.gif'});

						   
			/*$('table#dedicatedservers tr td').addClass('spec');*/
			
			$('table#dedicatedservers tr').each(function(index) {
  			$(this).children('td:first').addClass('spec');
			});
			$('table#dedicatedservers tr h3').parent('td').removeClass('spec');
			
			$('table#managedstorage tr').each(function(index) {
  			$(this).children('td:first').addClass('spec');
			});
			$('table#managedstorage tr h3').parent('td').removeClass('spec');
			
			
			
						   
			$('ul#tabs li.tab1').click(function() {
					$('div#tab1Content').show();
					$('div#tab2Content').hide();
					$('div#tab3Content').hide();
					$('ul#tabs li').removeClass('current');
					$(this).addClass('current');
			});
			$('ul#tabs li.tab2').click(function() {
					$('div#tab1Content').hide();
					$('div#tab2Content').show();
					$('div#tab3Content').hide();
					$('ul#tabs li').removeClass('current');
					$(this).addClass('current');
			});
			$('ul#tabs li.tab3').click(function() {
					$('div#tab1Content').hide();
					$('div#tab2Content').hide();
					$('div#tab3Content').show();
					$('ul#tabs li').removeClass('current');
					$(this).addClass('current');
			});
			$('ul#tabs li:first').addClass('current')

           
		   
		   
		   



                    $('.field-field-csdownload a').text('Download Case Study')



                    $('#hpbuttons li').click(function() {
                            var link = $(this).find('a').attr('href');
                            window.location = link;
                    })


                    $('#hpbuttons li').hover(
      function () {
        $(this).addClass('highlight');
      },
      function () {
         $(this).removeClass('highlight');
      }
    );


    $('#homepagePanels').simpleSlider();

    /** styling the megamenu bin **/
    $('.megamenu-menu li.megamenu-slot').css('background', 'transparent');

    $('ul.megamenu-bin').append($('<li />').css({
        width: '100%',
        height: '1px',
        backgroundColor: "#fff",
        margin: '10px 0 0'
    }));

    $('ul.megamenu-bin').prepend(
        $('<div />').css({
                width: '100%',
                height: '1500px',
                background: '#d8d8d8 url(' + theme_url + 'images/megamenu_bin_bg.jpg) top left no-repeat',
                position: 'absolute',
                top: '7px',
                left: 0,
                zIndex: 10001
            }).append($('<div />').css({
                width: '54px',
                height: '1500px',
                background: 'transparent url(' + theme_url + 'images/megamenu_bin_divider.png) top left repeat-y',
                position: 'absolute',
                left: '185px',
                zIndex: 10011
            })
        )
    );

    $('ul.megamenu-bin li').css({
        zIndex: 10021,
        position: 'relative'
    });
	
	
	
	
	
	

	

$('#mynetbenefit-account-login').validate({
	rules: {
		COID: {
			required: true
         },
		ExtraPwd: {
			required: true
		}                    
	},
	 messages: {
		COID: {
			required: "Please supply username"
		},
		ExtraPwd: {
			required: "Please supply password"
		}
	}
});

$('#mynetbenefit-controlpanel-login').validate({
	rules: {
		login_username: {
			required: true
         },
		login_password: {
			required: true
		}                    
	},
	 messages: {
		login_username: {
			required: "Please supply username"
		},
		login_password: {
			required: "Please supply password"
		}
	}
});
	
	








        //requires jquery validate plugin, see above.








	
	
	
	
	

});

/* SIMPLE SLIDER PLUGIN: simpleSlider

	Authored by: Damian Dawber
	Author Contact: damiandawber@googlemail.com

*/

(function($) {
	$.fn.simpleSlider = function(options) {
		var defaults = {
			interval: 4000
		};
		var opts = $.extend(defaults, options);
		
		return this.each(function() {
			var elm = this,
				numSlides = $(elm).children('li').length,
				slideWidth = $(elm).width(),
				slideHeight = $(elm).height();
				
			$(elm).width(slideWidth*(numSlides+1));
			
			$(elm).find('li:last').clone().prependTo($(elm));
			$(elm).css('left', -slideWidth);
			
			//add the slider buttons			
			var $sliderButtonsContainer = $('<div id="slide-buttons"></div>').css({
				overflow: 'hidden',
				position: 'absolute',
				bottom: '15px',
				right: '15px',
				background: 'transparent',
				zIndex: 1000,
				margin: 0,
				padding: 0
			});
			
			for(var i = 0; i < numSlides; i+=1) {
				$sliderButtonsContainer.append(
					$('<a></a>').css({
						cursor: 'pointer',
						background: 'url(images/slider_buttons.png)',
						backgroundPosition: (i === 0 ? '0 0' : '-17px 0'), 
						width: 17,
						height: 17,
						display: 'block',
						overflow: 'hidden',
						'float': 'left',
						margin: '0 5px 0 0'
					})
				);
			}
			
			var curSlide = 0;

			$(elm).parent().append($sliderButtonsContainer);
			
			function doEffect(goToSlide) {
				curSlide = curSlide === (numSlides - 1) ? 0 : curSlide + 1;
				
				$sliderButtonsContainer.find('a').css({
					backgroundPosition: '-17px 0'
				}).end().find('a').eq(curSlide).css({
					backgroundPosition: '0 0'
				});
				
				if(curSlide === 0) {
					$(elm).css('left', '0px');
				}
				
				if(typeof goToSlide !== 'undefined') {
					$(elm).animate({
						left: '-' + (slideWidth*(goToSlide + 1)) + 'px'
					}, 1000, function() {
						if(goToSlide === numSlides - 1) {
							$(elm).css('left', '0px');
						}
					});
				} else {homepagepopup
					$(elm).animate({
						left: '-=' + slideWidth + 'px'
					}, 1000);
				}				
			}
			
			var animInterval = setInterval(function() {
				doEffect();
			}, opts.interval);
			
			$('#slide-buttons a').click(function() {
				clearInterval(animInterval);
				//since curSlide is immediately incremented in doEffect(), pass
				//in the index of the clicked anchor MINUS one.
				doEffect($('#slide-buttons').find('a').index(this));
			});
		});
	}
	
	
	
	
	
	
	
	
	
	
	
	// BEGIN COASTDIGITAL
    //
    // This is a function that I "borrowed" from the urchin.js file.
    // It parses a string and returns a value.  I used it to get
    // data from the __utmz cookie
    //
    function _uGC(l,n,s) {
     if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
     var i,i2,i3,c="-";
     i=l.indexOf(n);
     i3=n.indexOf("=")+1;
     if (i > -1) {
      i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
      c=l.substring((i+i3),i2);
     }
     return c;
    }

    // 
    // Get the __utmz cookie value. This is the cookies that 
    // stores all campaign information. 
    // 
    var z = _uGC(document.cookie, '__utmz=', ';'); 
    // 
    // The cookie has a number of name-value pairs. 
    // Each identifies an aspect of the campaign. 
    // 
    // utmcsr  = campaign source 
    // utmcmd  = campaign medium 
    // utmctr  = campaign term (keyword) 
    // utmcct  = campaign content  
    // utmccn  = campaign name 
    // utmgclid = unique identifier used when AdWords auto tagging is enabled 
    // 
    // This is very basic code. It separates the campaign-tracking cookie 
    // and populates a variable with each piece of campaign info. 
    // 
    var source  = _uGC(z, 'utmcsr=', '|'); 
    var medium  = _uGC(z, 'utmcmd=', '|'); 
    var term    = _uGC(z, 'utmctr=', '|'); 
    var content = _uGC(z, 'utmcct=', '|'); 
    var campaign = _uGC(z, 'utmccn=', '|'); 
    var gclid   = _uGC(z, 'utmgclid=', '|'); 
    // 
    // The gclid is ONLY present when auto tagging has been enabled. 
    // All other variables, except the term variable, will be '(not set)'. 
    // Because the gclid is only present for Google AdWords we can 
    // populate some other variables that would normally 
    // be left blank. 
    // 
    if (gclid !="-") { 
          source = 'google'; 
          medium = 'cpc'; 
    } 
    // Data from the custom segmentation cookie can also be passed 
    // back to your server via a hidden form field 
    var csegment = _uGC(document.cookie, '__utmv=', ';'); 
    if (csegment != '-') { 
          var csegmentex = /[1-9]*?\.(.*)/;
          csegment    = csegment.match(csegmentex); 
          csegment    = csegment[1]; 
    } else { 
          csegment = '(not set)'; 
    } 
     
    //
    // One more bonus piece of information.  
    // We're going to extract the number of visits that the visitor
    // has generated.  It's also stored in a cookie, the __utma cookis
    // 
    var a = _uGC(document.cookie, '__utma=', ';');
    var aParts = a.split(".");
    var nVisits = aParts[5];

    function populateHiddenFields(f) 
    { 
          f.source.value  = source; 
          f.medium.value  = medium; 
          f.term.value    = term; 
          f.content.value = content; 
          f.campaign.value = campaign; 
          f.segment.value = csegment; 
          f.numVisits.value = nVisits;


          return validateRequired(); 
    } 
// END COASTDIGITAL

	
	
	
	


	
	
	
	
	
})(jQuery);

