var loading = 'Loading..';
$(function() 
	{
	Condition();
	showMaterial();
	showHelp();
	Showcalculator();
	scrollTicker('div.ticker');
	});
//------------------------------------------------------------------------------
function showMaterial(){
  $('#matlist li[rel], .pixtip img[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
			   text: ($(this).text())?$(this).text():$(this).parent().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 = $(".searchform select");
	sel.change(function(){
		$(this).parent("form.searchform").submit();
	});
}
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){
	FIFO.updateCookie(name_in+'&'+img_in);	
}
function fifo(){
	this.fifoSize = 4; //0 based, total 4recs
	this.fifoArr = new Array();
	this.flatArr = new String();
	this.CookieName = "recent";
	//methods
	this.pushArr = ArrayPush;
	this.popArr = ArrayPop;
	this.toArr = ArrayBuild;
	this.fromArr = ArrayFlat;
	this.updateCookie = UpdateCookie;
	this.additem = AddItem;
}
function ArrayPush(value_in ){
	this.fifoArr.push(value_in);
}
function ArrayPop(){
	this.fifoArr.shift();
}
function ArrayBuild(){
	this.fifoArr = String(this.flatArr).split("#");
}
function ArrayFlat(){
	this.flatArr = this.fifoArr.join("#");
}
function AddItem(value_in){
	//console.info("AddItem:getCookie: Name:"+this.CookieName+" value:"+value_in+" Current Cookie Contnet:"+this.flatArr);
	if(this.flatArr!= "") this.toArr();
	this.pushArr(value_in);
    //console.info("UpdateCookie:Pushed:"+value_in+" length:"+this.fifoArr.length);
    if(this.fifoArr.length > this.fifoSize) {
		this.popArr();
		 //console.info("UpdateCookie:popped length:"+this.fifoArr.length);
	}
    this.fromArr();
	//console.info("UpdateCookie:done:"+this.flatArr);
}
function UpdateCookie(value_in){
 //console.info("UpdateCookie");
 this.flatArr = getCookie(this.CookieName);
 //console.info('index:'+this.flatArr.indexOf(value_in));
 if(this.flatArr.indexOf(value_in) == -1){ //this item not already in teh cookie
  this.additem(value_in);
  var today = new Date();
  var expires = new Date();
  expires.setTime(today.getTime() + 1000*60*60*24*30); // expires in a month
  document.cookie = this.CookieName + "=" + escape(this.flatArr) + "; expires=" + expires.toGMTString() +";path=/";
 }
 }
FIFO = new fifo();
function scrollTicker(class_in){

$(class_in).vTicker({
   speed: 800,  //700
   pause: 3500,  //4000
   showItems: 3, //2
   animation: 'fade' //,
 //  mousePause: false, //true
  //height: 0, //0 off
  // direction: 'up' //up
});
	$('div.ticker #ticker').css('visibility','visible');

}
var addthis_config = {
     ui_cobrand: "Czar Floors",
	 data_track_clickback: true	
}

