$.fn.log = function (msg) {
      if (console)
      {
      	console.log("%s: %o", msg, this);
   
   	return this;
     }
};
  
$(function() {
	
	$.preload([ 'logo', 'revamp-collection', 'revamp-collection-over', 'revive-collection', 'revive-collection-over' ], {
	    base:'images/',
	    ext:'.gif'});

	var r = Raphael("furniture-navigation-canvas", 840, 110);
	
	var reviveCollection = r.image("images/revive-collection.gif", 456, 20, 103, 77).attr({cursor: "pointer"});
	var reviveCollectionHref = $('nav ul li.furniture ul li a').first().attr("href");
	reviveCollection.hide();
	reviveCollection.mouseout(function (e) {
	    this.attr({src: "images/revive-collection.gif"});
	}).mouseover(function (e) {
	    this.attr({src: "images/revive-collection-over.gif"});
	}).mouseup(function (e) {
		this.attr({src: "images/revive-collection.gif"});
	}).click(function (e) {
	   document.location = reviveCollectionHref; //"revive-collection.shtml"
	});	
	
	
	var revampCollection = r.image("images/revamp-collection.gif", 570, 30, 101, 77).attr({cursor: "pointer"});
	var revampCollectionHref = $('nav ul li.furniture ul li a').last().attr("href");
	revampCollection.hide();
	revampCollection.mouseout(function (e) {
	    this.attr({src: "images/revamp-collection.gif"});
	}).mouseover(function (e) {
	    this.attr({src: "images/revamp-collection-over.gif"});
	}).mouseup(function (e) {
		this.attr({src: "images/revamp-collection.gif"});
	}).click(function (e) {
	   document.location = revampCollectionHref;// "revamp-collection.shtml"
	});
	
	// remove subnav from DOM as now handled above
	$('nav ul li.furniture ul').remove();
	
	// hide furniture mouseover assets
	$('nav ul li a').mouseover(function (e) {
	   	revampCollection.hide();
	 	reviveCollection.hide();
	    return this;
	});
	
	// show furniture mouseover assets
	$('nav ul li.furniture').css('cursor','pointer');
	$('nav ul li.furniture').mouseover(function (e) {
	    e.preventDefault();
	   
	    revampCollection.show();
	    reviveCollection.show();
	    return this;
	});
	
	    	
	$('.wrapper').mousemove(function (e) {
		var x = e.pageX - this.offsetLeft;
        var y = e.pageY - this.offsetTop;
       // console.log("X: " + x + " Y: " + y);     
		if (y > 140 || x < 453|| x > 673 )
		{
			revampCollection.hide();
	    	reviveCollection.hide();
		}
		
		return this;
	});

    checkToDisplayIENote();
});

function emailMe (subject)
{
	//console.log("subject = " + subject);
	var mailto_link = 'mailto:info@woodpop.co.uk?subject='+subject.toUpperCase();

	win = window.open(mailto_link,'emailWindow');
	if (win && win.open &&!win.closed) win.close();

}

function isIE()
{
    return navigator.appName.indexOf('Internet Explorer') > 0 ||
        navigator.appName.indexOf('MSIE') > 0;
}

function checkToDisplayIENote()
{
    var query = unescape(location.search);
    if (isIE() || query.indexOf('ie-note') > 0) {
        var note = "<p class='ie-note'>"
                +'<strong>Notice:</strong> This site currently doesn\'t support Microsoft\'s Internet Explorer.'
                + ' Please use a different browser while we iron out the problems. Sorry for the inconvenience' + '<br/>'
                + '<br/>'
                + '<a href="http://www.mozilla.org/products/firefox">Mozilla Firefox</a>.' + '<br/>'
                + '<a href="http://www.google.co.uk/chrome">Google Chrome</a>.' + '<br/>'
                + '<a href="http://www.opera.com/">Opera</a>.' + '<br/>'
            + "</p>";
        $('.wrapper').append(note);
    }
}




