 $(function() 
	{
	Condition();
	showMaterial();
	showHelp();
	Showcalculator();
	show_recent();
	});
var loading = 'Loading..';
//------------------------------------------------------------------------------
function showMaterial(){
    $('#matlist li[rel]').each(function()
   {
      $(this).qtip(
      {
         content: 
		 {
            //text: '<img class="throbber" src="images/throbber.gif" alt="Loading..." />',
			text: '<img src="'+$(this).attr('rel')+'" />',
			title: {
               text: $(this).text() // Give the tooltip a title using each elements text
              }
         },
         position: {
            corner: {
               target: 'rightMiddle', // Position the tooltip above the link
               tooltip: 'leftMiddle'
                    },
            adjust: {
               screen: true // Keep the tooltip on-screen at all times
                   }
         },
         show: { 
            when: 'mouseover', 
            solo: true // Only show one tooltip at a time
         },
         hide: 'mouseout',
	     style: {
           tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
           border: {
			   width: 0,
               radius: 4
           },
            name: 'light',// Use the default light style
            width: 245
         }
      })
   });
}
//----------------------
function showHelp(){
   $('.helpicon[rel]').each(function()
   {
      $(this).qtip(
      {
         content: 
		 {
           	text: loading,
			url: 'tooltip.asp?id='+$(this).attr('rel'), 
		    title: {
              text: $(this).attr('title')
			   ,button: 'Close' 
			      }
         },
         position: {
            corner: {
               target: 'bottomLeft', 
               tooltip: 'topRight'
                    },
            adjust: {
               screen: true 
                   }
         },
         show: { 
            when: 'click', 
            solo: true 
         },
         hide: 'unfocus',
	     style: {
           tip: true, 
           border: {
			   width: 0,
               radius: 4
           },
           name: 'cream' ,
            width: 305 
         }
      })
   });	
 }
function Showcalculator(){
	$('.calcicon').click(function(){ 
		openWindow('calculator.asp?cat='+$(this).attr('rel'),'600','540');
									})
}
function Condition(){
	var sel = $("select.condition");
	HighlightSelect(sel);
	sel.change(function(){
		$(this).parent("form.searchform").submit();
	});
}
function HighlightSelect(sel_in){
if(sel_in.id!="sku"){
	sel_in.each(function(){
	if($(this).val() != "") {
		  $(this).addClass('changedSelect').children(".firstOption").text("All");
	}
 });
}
}
function addtofav(linkUrl,linkTitle){
   if (!document.all) {
      alert('Please hit Ctrl+D to Bookmark this page');
   } else {external.AddFavorite(linkUrl,linkTitle);}
   return false;
}
function isEmail(strEmail){
	return ( strEmail.search( /\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}/ ) != -1); 
}
function openWindow(page, width, height) {
    if (!window.window2) {
       var window2 = window.open(page,'windowRef','width='+ width + ', height=' + height);
    }
    else {
       if (!window2.closed) {
          window2.focus();
        }
        else {
            window2 = window.open(page,'windowRef','width=' + width + ', height=' + height);
        }
    }
}
function printit(){
    if (window.print) {
        window.print() ;
    } else {
        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
        WebBrowser1.ExecWB(6, 1);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";
    }
}
function openEmailform(){
	var eurl = document.location;
    var win = 'emailtofriend.asp?eurl='+eurl;
		 return openWindow(win,350,600);
	 }  
//Recently viewed code
function setCookie(name, value) {   
		 var today = new Date();
		 var expires = new Date();
		 expires.setTime(today.getTime() + 1000*60*60*24*30); // expires in a month
		 document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +";path=/";
		}
function getCookie(Name) {
		 var search = Name + "=";
		 if(document.cookie.length > 0) {
		  var offset = document.cookie.indexOf(search);
		  if(offset != -1) {
		   offset += search.length;
		   var end = document.cookie.indexOf(";", offset);
		   if(end == -1) {
			   end = document.cookie.length;
			   }
		 return unescape(document.cookie.substring(offset, end));
		 }
		else return "";
		}
	  }
function capture_item(img_in, name_in){
	var proIMAGE='<img src="/_private/pictures/thumbnails/'+img_in+'" title="hardwood and stone floor inlay" alt="Floor inlays, medallions, borders and parquet" \/>';
	var proNAME='<div class="itemName">'+name_in+'<\/div>';
	var p0='<div class="viewed"><a href="item_details.asp?sku='+name_in+'">'+proIMAGE+'<br\/>'+proNAME+'</a><\/div>';
	//alert(name_in+","+img_in);
		    var p1=getCookie("p1");
			var p2=getCookie("p2");
			var p3=getCookie("p3");
			var p4=getCookie("p4");
		if(p0 !=null && p0 != p1 && p0 != p2 && p0 != p3 && p0 !=p4){
			setCookie("p1",p0);
			setCookie("p2",p1);
			setCookie("p3",p2);
			setCookie("p4",p3);
		}  
}
function show_recent() {
	    var str = "";
		var p1=getCookie("p1");
		var p2=getCookie("p2");
		var p3=getCookie("p3");
		var p4=getCookie("p4");
		//alert(p1);
		if(p1){
			str = '<p id="recenttitle" class="faqLinks">Recently Viewed:</p>';
			}
		if (p1 !=null) {
			str +=p1;
			}
		if (p2) {
			str +=p2;
			}
		if (p3) {
			str +=p3;
			}
		if (p4) {
			str +=p4;
			}
	    if (p1) {
    //document.write(str);
	$("#recent").html(str);
		}
}

