$(document).ready(function() {
  $('#hinSearch_divSearch').css('left',-439);
  initSidebar();
  rotator();
  $('.hide').hide();
  $('.moreLink').click(function() {
	$(this).hide();
	$(this).next().show(150);
	return false;
  })
  $('.lessLink').click(function() {
	$(this).parent().hide(150);
	$(this).parent().prev().show();
	return false;
  })
  $('.searchInput').Watermark('KEYWORDS');
  if (document.all) {
    $(".tl, .tm, .tr, .bl, .bm, .br, .wrapper").hoverClass("sfHover");
  }
  if($('#homeLifestyleImg')[0].offsetWidth == 710) {
	$('.replaceThis').each(function() {
	  theId = $(this).parent().parent().attr('id');
	  string = $(this).text();
	  filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
	  if(theId=='sidebar') {
		  $(this).html('<img src="/images/headers/sidebar/' + filename + '.gif" alt="' + string + '" />'); 
	  } else {
		  $(this).html('<img src="/images/headers/' + filename + '.gif" alt="' + string + '" />');
	  }
	});
  }
  var date = parseInt($('#copyrightDate').text());
  var yr = new Date().getFullYear();
  if(date<yr) {
	$('#copyrightDate').text(yr);  
  } else {
	$('#copyrightDate').text(date);
  }
  $('#closeLink a').click(function() {
  	AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup();
	return false;			   
  })
  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function() {
	$('#closeLink a').click(function() {
  	AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup();
	return false; })																	
  })
})
$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};
function initSidebar() {
	var snippet = sidebar2();
	$('#newProducts').html(snippet);
	var num = Math.floor(Math.random()*7)+1;
	$('#sidebarNewProduct').attr('src','images/sidebar-new-product-'+num+'.jpg');
	snippet = sidebar();
	$('#landscapeLighting').html(snippet);
}
function rotator() {
	var pics = new Array();
	$.ajax({
    	type: "GET",
    	url: "/scripts/home-rotator.xml",
    	dataType: "xml",
    	success: function(xml) {
			var count = 0;
			$(xml).find('product').each(function() { 
				var pic = '<a href="products/product-detail.aspx?pid='+$(this).find('pid').text()+'" title="See details for this product"><img src="images/lifestyle-pics/'+$(this).find('src').text()+'" alt="Product shown - '+$(this).find('name').text()+'" name="homeLifestyleImg" width="710" height="743" id="homeLifestyleImg" /></a>';
				pics[count] = pic;
				count++;
			})
			var show = Math.floor(Math.random()*pics.length);
			$('#mainContent').html(pics[show]);
		}
	})
}
var topSnippets = new Array();
topSnippets[0] = '<h3 class="replaceThis">New Products</h3><a href="products/familyfinish.aspx?cid=n"><img src="" alt="New Products" height="142" width="230" id="sidebarNewProduct" /></a><p><strong>Light does many things.</strong><br /> Our days rise and set by it. It soothes. It uplifts. It illuminates our lives - from small everyday moments, to momentous occasions. <a href="#" class="moreLink">More &gt;</a> <span class="hide">Throughout our days, throughout our homes, light helps us see. It allows us to notice the details, draws attention to what really matters. LIGHTING INSPIRES. It shines as a focal point. It\'s the spark that comes first, and subsequently illuminates everything - and everyone - it touches. <a href="products/families.aspx?cid=n">View our new products</a><br /><a href="#" class="lessLink">&lt; Hide</a></span></p>';
topSnippets[1] = '<h3 class="replaceThis">$5000 Hinkley Home Makeover</h3><a href="homemakeover/"><img src="images/sidebar-home-makeover.gif" alt="New Products" height="144" width="230" /></a><p><a href="homemakeover/"><strong>Click to enter</strong></a></p>';
var snippets = new Array();
snippets[0] = '<h3 class="replaceThis">Landscape Lighting</h3><a href="/products/families.aspx?cid=9"><img src="/images/sidebar-landscape-lighting.jpg" alt="Landscape Lighting" height="142" width="230" /></a><p><strong><em>Night</em> AGLOW.</strong><br /> Hinkley provides a collection of decorative and functional landscape lighting to help you complete your home\'s lighting plan. <a href="#" class="moreLink">More &gt;</a> <span class="hide">Whether you choose to highlight architectural features of your home, extend your living space by illuminating your landscaping, or accentuate an object of interest, we have the perfect fixture that will meet your lighting needs. Your imagination is your only limitation in lighting your landscape.  <a href="/products/families.aspx?cid=9">View our landscape products</a><br /><a href="#" class="lessLink">&lt; Hide</a></span></p>';
snippets[1] = '<h3 class="replaceThis">Eco-Options</h3><a href="/products/energy-saving.aspx"><img src="/images/sidebar-go-green.jpg" alt="Go Green With Hinkley Lighting" height="142" width="230" /></a><p>Hinkley offers a variety of options that allow you to design an outdoor lighting plan with the environment in mind, including Energy Saving, Dark Sky, and Energy Star qualified fixtures. <a href="/products/energy-saving.aspx">Read about our Eco-Options</a>';

function sidebar() {
	return(snippets[Math.floor(Math.random()*2)]);
}
function sidebar2() {
	return(topSnippets[0]);	
}