var visitorid=document.getElementById("visitorid").innerHTML;
var pagetype=document.getElementById("pagetype").innerHTML;
var my1='#'+document.getElementById("my1").innerHTML;
var my2='#'+document.getElementById("my2").innerHTML;
var my3='#'+document.getElementById("my3").innerHTML;
var my4='#'+document.getElementById("my4").innerHTML;
var my22=document.getElementById("my22").innerHTML;

var in_scaleval=document.getElementById("in_scaleval").innerHTML;
var in_maxscale=document.getElementById("in_maxscale").innerHTML;

var mclass=document.getElementById("mclass").innerHTML;
var shardsku=document.getElementById("shardsku").innerHTML;
var elecsku=document.getElementById("elecsku").innerHTML;
var stockedid=document.getElementById("my22").innerHTML;
var currentstep=$('#currentstep').html();
var substep=$('#substep').html();
var showcustom=$('#showcustom').html();
var pagetype=$('#pagetype').html();


$(function() {
	//sets up dialogs
	$('#tooMany').dialog({ autoOpen: false });
	$('#alreadyThere').dialog({ autoOpen: false });
	$('#moreColors').dialog({ autoOpen: false });
	$('#dragme').dialog({ autoOpen: false });
	$('#nocan').dialog({ autoOpen: false });
	$('#choosePattern').dialog({ autoOpen: false });

	$('#ajaxDialog').dialog({ 
	autoOpen: false,
	modal: true,
	width:700,
	height: 500,
	overflow:scroll,
	position:'top'});

		$('#zoomDialog').dialog({ 
		autoOpen: false,
		modal: true,
		width:400,
		height: 500,
		overflow:scroll,
		position:'top'});





///slider


$("#scaleslider").slider({
value:in_scaleval,
min: 100,
max: in_maxscale,
step: 100,
change: function(event, ui) {
if (ui.value=='500')
{var myscale='50'
 var scaletype='Largest'}
else if (ui.value=='400')
{var myscale='100'
 var scaletype='Large'}
else if (ui.value=='300')
{var myscale='200'
 var scaletype='Medium'}
else if (ui.value=='200')
{var myscale='400'
 var scaletype='Small'}
else if (ui.value=='100')
{var myscale='800'
 var scaletype='Tiny'}
 
//stores stuff
document.getElementById("in_scaleval").innerHTML=ui.value;
$.cookie(("myscale"), myscale);
document.getElementById("scaletype").innerHTML=scaletype;
changeme('pattern_scale',myscale,document.getElementById('pat_sku').innerHTML,document.getElementById("thispattern").innerHTML);
return false;
}

});

////slider
function loadPat(){
loadTips(pagetype+"-cp-default");



    $.ajax({
    
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/patternsinc.asp",
                   success: function(data) {
                   $("#pgallery").html(data).hide().fadeIn('slow');
		         if (document.getElementById("my6").innerHTML=='')
			 {
			 $('#favetable').addClass('ui-state-disabled');
			 
			 $('#patternbox').addClass('ui-state-disabled');
			 }
			 else
			 {
			 var pat=document.getElementById("pat_sku").innerHTML;
			 var my6='#'+document.getElementById("my6").innerHTML;
			 favePattern($(my6),pat,false);
			 }
			 hiliteP();
			pgalleryclick();
			 reCustom();
			 reStock();
			 
			 

		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert("problem")
		       }

                 }); 


}



$('#patterntypes').change(function(){ 
loadTips(pagetype+"-cp-"+$("#patterntypes").val(),($(this).find('option').filter(':selected').text()));

    $.ajax({
    
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/patternsinc.asp",
                   data: "thisfilter=" + $("#patterntypes").val(),
                   success: function(data) {
                   $("#pgallery").html(data).hide().fadeIn('slow');
		         hiliteP();
			pgalleryclick();
		   
		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert("problem")
		       }

                 }); 


});

function loadColors(){
$('#thissample').removeClass('sample');
$('#thissample').addClass('strikeoff');
loadTips(pagetype+"-cc-default");

    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/colorsinc.asp?thisfilter=all",
                   success: function(data) {
                   $("#gallery").html(data).hide().fadeIn('slow');
		         hilite();
			 galleryclick();
			 addFaves(false);
			 zoom();
			$('li',$gallery).draggable({
			containment: '#colorarea',
			revert: 'invalid',
			helper: 'clone',
			cursor: 'move',
			stop: function(){remhi()},
			start: function(){
			if ($('#favepat li').attr("numcolors")==2)
			{
			$('#fave1').addClass('ui-state-highlight');
			$('#fave2').addClass('ui-state-highlight');
			//$('#faveHelp1').addClass('ui-state-highlight');
			//$('#faveHelp2').addClass('ui-state-highlight');
			}
			else if ($('#favepat li').attr("numcolors")==3)
			{
			$('#fave1').addClass('ui-state-highlight');
			$('#fave2').addClass('ui-state-highlight');
			$('#fave3').addClass('ui-state-highlight');
			
			//$('#faveHelp1').addClass('ui-state-highlight');
			//$('#faveHelp2').addClass('ui-state-highlight');
			//$('#faveHelp3').addClass('ui-state-highlight');
			}
			
			else if ($('#favepat li').attr("numcolors")==4)
			{
			$('#fave1').addClass('ui-state-highlight');
			$('#fave2').addClass('ui-state-highlight');
			$('#fave3').addClass('ui-state-highlight');
			$('#fave4').addClass('ui-state-highlight');
			
			//$('#faveHelp1').addClass('ui-state-highlight');
			//$('#faveHelp2').addClass('ui-state-highlight');
			//$('#faveHelp3').addClass('ui-state-highlight');
			//$('#faveHelp4').addClass('ui-state-highlight');
			}
			}
			})
		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert("problem")
		       }

                 }); 


}












$('#colortypes').change(function(){ 
loadTips(pagetype+"-cc-"+$("#colortypes").val(),($(this).find('option').filter(':selected').text()));
 

    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/colorsinc.asp",
                   data: "thisfilter=" + $("#colortypes").val(),
                   success: function(data) {
                   $("#gallery").html(data).hide().fadeIn('slow');
		         hilite();
			 galleryclick();
			 zoom();
			 $('li',$gallery).draggable({
			 containment: '#colorarea',
			 revert: 'invalid',
			 helper: 'clone',
			cursor: 'move'
		   });

		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert("problem")
		       }

                 }); 


});


function loadTrim(){

 $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/trimsinc.asp?baseprice="+$('#mybaseprice').html(),
		    beforeSend: function(){
	      		$("#trims-ul").html('<img src=http://www.alluminare.com/images/wizloader.gif style="position:absolute;top:200px">');
	      		},                  
                  
                   success: function(data) {
                   
                   $("#trims-ul").html(data).hide().fadeIn('slow');
                   addTrim();
		    loadTips(pagetype+"-t-default");
      		    makehover();
		    clickbutton();
		    zoom();
			},
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert(XMLHttpRequest)
		       }
           	
                 
                 }); 
}





$('#trimtypes').change(function(){ 
loadTips(pagetype+"-t-"+$("#trimtypes").val(),($(this).find('option').filter(':selected').text()));



    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/trimsinc.asp",
                   data: "thisfilter=" + $("#trimtypes").val()+"&baseprice="+$('#mybaseprice').html(),
		    beforeSend: function(){
	      		$("#trims-ul").html('<img src=http://www.alluminare.com/images/wizloader.gif style="position:absolute;top:200px">');
	      		},                  
                  
                   success: function(data) {
                   
                   $("#trims-ul").html(data).hide().fadeIn('slow');
                   
		    makehover();
		    clickbutton();
		    zoom();
			},
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert(XMLHttpRequest)
		       }
           	
                 
                 }); 


});



function loadStocked(){
$('#thissample').removeClass('strikeoff');
$('#thissample').addClass('sample');

loadTips(pagetype+"-m-default");



 $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/stockedinc.asp?thisid="+stockedid+"&baseprice="+$('#mybaseprice').html()+"&shape="+$('#shape').html()+"&widthclass="+$('#widthclass').html(),
                   beforeSend: function(){
                   $("#stocked").html('<img src=http://www.alluminare.com/images/wizloader.gif style="position:absolute;top:200px">');
                   },
                   
                   success: function(data) {
                   $("#stocked").html(data).hide().fadeIn('slow');
                    addStock();
                    makehover();
		    clickbutton();
		    reCustom();
		    reStock();
		    zoom();
			},
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert(errorThrown)
		       }
           	
                 
                 }); 

};



$('#stocktypes').change(function(){ 
loadTips(pagetype+"-m-"+$("#stocktypes").val(),($(this).find('option').filter(':selected').text()));

    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/stockedinc.asp",
                   data: "thisfilter=" + $("#stocktypes").val()+"&baseprice="+$('#mybaseprice').html()+"&shape="+$('#shape').html()+"&widthclass="+$('#widthclass').html(),
                   beforeSend: function(){
                   $("#stocked").html('<img src=http://www.alluminare.com/images/wizloader.gif style="position:absolute;top:200px">');
                   },
                   
                   success: function(data) {
                   $("#stocked").html(data).hide().fadeIn('slow');
                      makehover();
		    clickbutton();
		    reCustom();
		    reStock();
		    zoom();
			},
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert(errorThrown)
		       }
           	
                 
                 }); 


});







function loadSus(){ 
loadTips(pagetype+"-s-default");


    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/suspensionsinc.asp",
                   data: "thisfilter=" + $("#sustypes").val()+"&sku="+$('#sku').html(),
                   beforeSend: function(){
	      		$("#suspensions-ul").html('<img src=http://www.alluminare.com/images/wizloader.gif style="position:absolute;top:200px">');
	      		},

                   
                   success: function(data) {
                   $("#suspensions-ul").html(data).hide().fadeIn('slow');
    			addSus();
    			makehover();
    			clickbutton();
    			help();
		        
		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert("problem")
		       }

        }); 

};



$('#sustypes').change(function(){ 
loadTips(pagetype+"-s-"+$("#sustypes").val(),($(this).find('option').filter(':selected').text()));

    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/suspensionsinc.asp",
                   data: "thisfilter=" + $("#sustypes").val()+"&sku="+$('#sku').html(),
     			beforeSend: function(){
	      		$("#suspensions-ul").html('<img src=http://www.alluminare.com/images/wizloader.gif style="position:absolute;top:200px">');
	      		},
                 
                  
                  success: function(data) {
                   $("#suspensions-ul").html(data).hide().fadeIn('slow');

		         makehover();
			 clickbutton();
			 help();
			},
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert(XMLHttpRequest)
		       }

                 }); 


});




function loadWid(){ 
loadTips(pagetype+"-w-default");
loadReview();


    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/chooserinc.asp",
                   data: "sku="+$('#sku').html(),
                   success: function(data) {
                   $("#wid-ul").html(data).hide().fadeIn('slow');
    			addWid();
    			makehover();
    			clickbutton();
    			help();
		        
		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert("problem")
		       }

        }); 

};



$('#wids').change(function(){ 
loadTips(pagetype+"-w-"+$("#wids").val(),($(this).find('option').filter(':selected').text()));

    $.ajax({
                   type: "GET",
                   url: "http://www.alluminare.com/includes/rule2/chooserinc.asp",
                   data: "thisfilter=" + $("#wids").val()+"&sku="+$('#sku').html(),
                   success: function(data) {
                   $("#wid-ul").html(data).hide().fadeIn('slow');

		         makehover();
			 clickbutton();
			 help();
			},
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         alert(XMLHttpRequest)
		       }

                 }); 


});








function addtoFavorite (del,thisid){ 
if (del=='1')
{
thisdata="del=1&thisid="+thisid+"&visitorid="+visitorid
}
else
{
thisdata="sku="+document.getElementById("sku").innerHTML+"&pagetype="+pagetype+"&visitorid="+visitorid
}


    $.ajax({
                   type: "POST",
                   url: "tagme_withpic7.asp",
                   data: thisdata,
                   success: function(data) {
				if (del=='1')
				{
				$(data).remove();
				}
				else
				{
				if ($("#favearea div").length<20)
					{
					$("#startdesign").addClass('hid');
					//$('#favearea').prepend(data);
                   $("#favearea").prepend(data).hide().fadeIn('slow');
                   

					}
					else
					{
					$("#tooMany").dialog('open');
					}
				delthis();


				}
                      
                        
		         
		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		        // alert("problem")
		       }


                 }); 

return false;
};
function changeme (changethis,changethisto,pattern_sku,thistitle){ 
$('#mainimg').fadeOut("slow");

$('#imgloaderpic').removeClass("hid").fadeIn();
    $.ajax({
                   type: "POST",
                   url: "parser8.asp",
                   data: "pm=img&title="+escape(thistitle)+"&changethis="+changethis+"&changethisto="+changethisto+"&pattern_sku="+pattern_sku+"&visitorid="+visitorid,
             
                   
                   success: function(data) {
                   
	       	 $('#mainimg').load(function () {
	            
	            $(this).fadeIn("slow");
	            $('#imgloaderpic').addClass("hid").fadeOut("slow")

	            }).attr('src', data);
    			

		         
		       },
		  	
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert("problem")
		       }

                 }); 
                 
                 
        $.ajax({
                   type: "POST",
                   url: "parser8.asp",
                   data: "pm=el&title="+escape(thistitle)+"&changethis="+changethis+"&changethisto="+changethisto+"&pattern_sku="+pattern_sku+"&visitorid="+visitorid,
                   success: function(data) {
                       /////
                       var stuff = data
			morepieces = new Array;
			pieceHolder = new Object()
			pieceHolder.pieces = new Array()
			pieceHolder.vals = new Array()

			function Breakpieces()
			{
			var pieces = stuff.split('&')
			for(i=0; i!=pieces.length; i++)
			{
			morepieces[i] = pieces[i].split('=')
			pieceHolder.pieces[i] = morepieces[i][0]
			pieceHolder.vals[i] = morepieces[i][1]

			}
			}

			Breakpieces()

			for(i=0;i<morepieces.length;i++)
			{
				if (pieceHolder.pieces[i]=="fabricnamehead")
				{
				document.title=document.getElementById("totitle").innerHTML+" "+pieceHolder.vals[i]
				}

			   if (pieceHolder.pieces[i]=="saleprice_cart")
				{
				document.getElementById("total").setAttribute("class", "crossout");
				document.getElementById("sale").setAttribute("class", "bigred");
				}
				else
				{
				document.getElementById("total").setAttribute("class", "bigblack");
				document.getElementById("sale").setAttribute("class", "hid");
				}



			//alert(pieceHolder.pieces[i])
			document.getElementById(pieceHolder.pieces[i]).innerHTML=pieceHolder.vals[i]


			}

                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       ////
                       
		         
		       },
		       error: function (XMLHttpRequest, textStatus, errorThrown) {
		         //alert("problem")
		       }

                 }); 
            


};





var recycle_icon = '<a href="#" title="Delete (not forever, though)" class="ui-icon ui-icon-trash">Recycle image</a>';

var $gallery = $('#gallery'), $trash = $('#trash'),$favecolors = $('#favecolors'),$fave1 = $('#fave1'),$fave2 = $('#fave2'),$fave3 = $('#fave3'),$fave4 = $('#fave4'),$pgallery = $('#pgallery'), $ptrash = $('#ptrash'),$faveP = $('#faveP'),$shortlist=$('#shortlist'),$faveS=$('#faveS'), $shortlistT=$('#shortlist-t'),$faveT=$('#faveT');




//draggables
$('li',$trash).draggable({
cancel: 'a.ui-icon',
containment: '#patternarea',
snap: '#faves',
revert: 'invalid',
helper: 'clone',
cursor: 'move'
});




$('li',$ptrash).draggable({
cancel: 'a.ui-icon',
containment: '#patternarea',
snap: '#selectedpat',
revert: 'invalid',
helper: 'clone',
cursor: 'move'
});



//droppables begin

//general function to remove color side hilites
function remhi(){
$('#fave1').removeClass('ui-state-highlight');
$('#fave2').removeClass('ui-state-highlight');
$('#fave3').removeClass('ui-state-highlight');
$('#fave4').removeClass('ui-state-highlight');
$('#favetable').removeClass('ui-state-highlight');
$(this).removeClass('ui-state-highlight');
}


$fave1.droppable({
activeClass: '.ui-state-highlight',

drop: function(ev, ui) {
var colorid=ui.draggable.attr('id');
//saveme("itemid=FC-"+colorid+"&itemloc=1&taggerid="+visitorid);
var colorid=ui.draggable.attr('id');
$("#fave1 li").remove();
remhi();
faveImage2(ui.draggable,$fave1,'custom_color1',true);
}
});	



$fave2.droppable({
activeClass: '.ui-state-highlight',

drop: function(ev, ui) {
			
var colorid=ui.draggable.attr('id');
//saveme("itemid=FC-"+colorid+"&itemloc=2&taggerid="+visitorid);
var colorid=ui.draggable.attr('id');
$("#fave2 li").remove();
remhi();
faveImage2(ui.draggable,$fave2,'custom_color2',true);

}
});						

$fave3.droppable({
activeClass: '.ui-state-highlight',

drop: function(ev, ui) {
if ($(this).attr('class')=='ui-droppable ui-state-disabled')
{
$("#moreColors").dialog('open');
}


else
{						

var colorid=ui.draggable.attr('id');
var colorid=ui.draggable.attr('id');
$("#fave3 li").remove();
remhi();
faveImage2(ui.draggable,$fave3,'custom_color3',true);
}
}
});						

$fave4.droppable({
activeClass: '.ui-state-highlight',
drop: function(ev, ui) {
if ($(this).attr('class')=='ui-droppable ui-state-disabled')
{
$("#moreColors").dialog('open');
}

else
{						
var colorid=ui.draggable.attr('id');
var colorid=ui.draggable.attr('id');
$("#fave4 li").remove();
remhi();
faveImage2(ui.draggable,$fave4,'custom_color4',true);
}
}
});





						


///fave images




function faveImage2($item,faveid,colid,dochange) {
var $list = $('ul',faveid).length ? $('ul',faveid) : $('<ul class="ui-helper-reset"/>').appendTo(faveid);
var copy = $item.clone();

copy.appendTo($list).fadeIn(function() {
copy.animate({ width: '40px',height:'40px' }).find('img').animate({ height: '40px',width: '40px' });
$item.removeClass('ui-state-highlight');
copy.removeAttr('style'); 
copy.attr('id', 'FC-'+copy.attr('id'));
copy.css('cursor', 'crosshair');
copy.removeClass('ui-state-highlight');

});


var colorid=$item.attr('colorid');
var colorname=$item.attr('thistitle');
var pat_sku=$('#pat_sku').html();
		if (pat_sku.length)
		{
		//do nothing
		}
		else
		{
		pat_sku=$.cookie('patsku')
		}
if (dochange==true)
{
changeme(colid,colorid,pat_sku,colorname);
$.cookie(faveid.attr("id"), colorid);

}
};





function favePattern($item,patid,dochange) {
var $list = $('ul',$faveP).length ? $('ul',$faveP) : $('<ul id="favepat" class="favepats pgallery ui-helper-reset"/>').appendTo($faveP);
var copy = $item.clone();
copy.appendTo($list).fadeIn(function() {
copy.attr('id', 'FP-'+copy.attr('id'));
copy.animate({ width: '60px',height:'80px' }).find('img').animate({ height: '50px',width: '50px' });
copy.css('cursor', 'crosshair');
copy.find('a.ui-icon-trash').remove();
copy.addClass('ui-widget-content')

});

var patid=$item.attr('patid');
var colorname=$item.attr('thistitle');

var ipsname=$item.attr('ipsname');
document.getElementById("thispattern").innerHTML=$item.attr('thistitle');
document.getElementById("pat_sku").innerHTML=ipsname;

numcolors=$item.attr("numcolors");
if (numcolors=='2')

{

$("#fave3").addClass('ui-state-disabled');
$("#fave4").addClass('ui-state-disabled');
$('#faveHelp3').html('(Not avail.)'); 
$('#faveHelp4').html('(Not avail.)'); 

}
else if (numcolors=='3'){
$("#fave3").removeClass('ui-state-disabled');
$("#fave4").addClass('ui-state-disabled');
$('#faveHelp3').html('(Detail 1)'); 

$('#faveHelp4').html('(Not avail.)'); 

}
else if (numcolors=='4'){
$("#fave3").removeClass('ui-state-disabled');
$("#fave4").removeClass('ui-state-disabled');
$('#faveHelp3').html('(Detail 1)'); 
$('#faveHelp4').html('(Detail 2)'); 

}

if (substep=="1")
{
dochange=true
}

if (dochange==true)
{
changeme('pattern_sku',ipsname,ipsname,colorname);

if ($item.attr('largest_ok')=='True')
{
$("#scaleslider").slider('option','max',500);
$("#scaleslider").slider("value",$.cookie("myscale"));

}
else
{
$("#scaleslider").slider('option','max',400);
}
$("#scaleslider").slider("value",$.cookie("myscale"));


}

};


function faveStock(thisid,dochange) {
if (substep==2)
{
dochange='True'
}

if (dochange=='True')
{
var materialid=$('#'+thisid).attr('fabid');
var materialname=$('#'+thisid).attr('thistitle');
changeme('standard',materialid,'',materialname)
}
$.cookie("stocked", materialid);

};



function faveTrim(thisid,dochange) {
var matno=$('#'+thisid).attr('matno');
var materialname=$('#'+thisid).attr('thistitle');


if (dochange=='True'){
changeme('bothtrims',matno,matno,materialname);
}

		
};				

function faveSus(thisid,dochange) {
var totale=$('#'+thisid).attr('totalemodel');
var totalh=$('#'+thisid).attr('totalhmodel');


if (dochange=='True'){
changeme('totalsuspension',totale,totalh,'')
}

		
};
function faveSize(thisid,dochange) {
var avlen=$('#'+thisid).attr('avlen');

if (dochange=='True'){
changeme('lensku',avlen,'',avlen)
}
}

function faveWid(thisid,dochange) {
var thisSku=$('#'+thisid).attr('mysku');

if (dochange=='True'){
changeme('modelno',thisSku,'','')
}
}

function faveDiff(thisid,dochange) {
if (dochange=='True'){
	if (thisid=='NODK'){
	changeme('diffsku','0000','','')
	}
	else
	{
	var dmodel=$('#'+thisid).attr('dmodel');
	var hmodel=$('#'+thisid).attr('totalhmodel');
	changeme('diffsku',dmodel,hmodel,'')
	}
}
}


///recyclers

// image recycleT function
function recycleImageT($item) {
$('#trimbox').removeClass('ui-state-highlight');
//saveme("itemid="+$item.attr('id')+"&itemloc=9&taggerid="+visitorid);
$item.remove();


};	





// image preview function, demonstrating the ui.dialog used as a modal window
function viewLargerImage($link) {
var src = $link.attr('href');
var title = $link.attr('mytitle');
var $modal = $('img[src$="'+src+'"]');
if ($modal.length) {
$modal.dialog('open')
} else {
var img = $('<img alt="'+title+'" width="500" height="400" style="display:none;padding: 8px;" />')
	.attr('src',src).appendTo('body');
setTimeout(function() {
	img.dialog({
			title: title,
			width: 500,
			position: 'top',
			modal: true
		});
}, 1);
}
};







// resolve the icons behavior with event delegation





function galleryclick(){
$('#gallery  li').click(function(ev) {
var $target = $(ev.target);
if ($target.is('.zoom')) {
zoom()
}
else
{
$("#dragme").dialog('open');
}
});
};





function reCustom(){
$('#PODselector').click(function() {
var url="http://www.alluminare.com/wiz.asp?step=1&substep=1&sku="+$('#sku').html()
location.href= url;
});
};



function reStock(){
$('#STANDselector').click(function() {
var url="http://www.alluminare.com/wiz.asp?step=1&substep=2&sku="+$('#sku').html()
location.href= url;
});
};


$('.strikeoff').click(function(ev) {
window.open('http://www.alluminare.com/strikeoff.asp?sku='+$('#sku').html());
});

$('.sample').click(function(ev) {
window.open('http://www.alluminare.com/buysamples.asp?sku='+$('#sku').html());
});



$('.savethis').click(function(ev) {
var $item = $(this);
var $target = $(ev.target);

addtoFavorite('0','0')

return false;
});

function delthis(){
$('.delthis').click(function(ev) {
var $item = $(this);
var $target = $(ev.target);
if ($target.is('a.ui-icon-trash')) {
addtoFavorite('1',$item.attr("delid"))
return false;
}

});
};




$('#step1').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=1&sku="+$('#sku').html()
location.href= url;
$("#currentstep").html("1")
});


$('#step2').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=2&sku="+$('#sku').html()
location.href= url
});




$('#step3').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=3&sku="+$('#sku').html()
location.href= url;
});

$('#step4').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=4&sku="+$('#sku').html()
location.href= url;
});

$('#step5').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=5&sku="+$('#sku').html()
location.href= url;
});

$('#step6').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=6&sku="+$('#sku').html()
location.href= url;
});

$('#step7').click(function(ev) {
var url="http://www.alluminare.com/wiz.asp?step=7&sku="+$('#sku').html()
location.href= url;

});

$('#prod_detail').click(function(ev) {
var url="http://www.alluminare.com/"+pagetype+".asp?sku="+$('#sku').html()
location.href= url;
});


$('#thisprev').click(function(ev) {
var cs=parseInt($('#currentstep').html())
var prev=cs-1
if (cs==1){
return false;
}
else
{
var url="http://www.alluminare.com/wiz.asp?step="+prev+"&sku="+$('#sku').html()
location.href= url;
}



});




$('#thisnext').click(function(ev) {

var cs=parseInt($('#currentstep').html())
var nextstep=cs+1
if (cs==7)
{

return false;
}

{
var url="http://www.alluminare.com/wiz.asp?step="+nextstep+"&sku="+$('#sku').html()
location.href= url;
}

});






function pgalleryclick(){

$('#pgallery  li').click(function(ev,target) {
var $target = $(ev.target);
if ($target.is('.zoom')) {
zoom()
}
else
{
//changes the big image
var $item = $(this);
var ipsname=$item.attr('ipsname')
var colorname=$item.attr('thistitle');
changeme('pattern_sku',ipsname,ipsname,colorname);
$.cookie('pat', $item.attr("id"));
$.cookie('patsku', $item.attr("ipsname"));

$("#faveP li").remove();

//appends to the slot
var $list = $('ul',$faveP).length ? $('ul',$faveP) : $('<ul id="favepat" class="favepats pgallery ui-helper-reset"/>').appendTo($faveP);
var copy = $item.clone();
copy.appendTo($list).fadeIn(function() {
copy.attr('id', 'FP-'+copy.attr('id'));
copy.animate({ width: '60px',height:'80px' }).find('img').animate({ height: '50px',width: '50px' });
copy.css('cursor', 'crosshair');
copy.find('a.ui-icon-trash').remove();
copy.addClass('ui-widget-content')
});

//removes hilites
$('#patterndrop').removeClass('ui-state-highlight');
$('#clickthis').removeClass('ui-state-highlight');

$(this).removeClass('ui-state-highlight');


var patid=$item.attr('patid');
var numcolors=$item.attr("numcolors");

document.getElementById("thispattern").innerHTML=$item.attr('title');
document.getElementById("pat_sku").innerHTML=ipsname;
//lock it down
if (numcolors=='2')

{

$("#fave3").addClass('ui-state-disabled');
$("#fave4").addClass('ui-state-disabled');
$('#faveHelp3').html('(Not avail.)'); 
$('#faveHelp4').html('(Not avail.)'); 

}
else if (numcolors=='3'){
$("#fave3").removeClass('ui-state-disabled');
$("#fave4").addClass('ui-state-disabled');
$('#faveHelp3').html('(Detail 1)'); 

$('#faveHelp4').html('(Not avail.)'); 

}
else if (numcolors=='4'){
$("#fave3").removeClass('ui-state-disabled');
$("#fave4").removeClass('ui-state-disabled');
$('#faveHelp3').html('(Detail 1)'); 
$('#faveHelp4').html('(Detail 2)'); 

}
//reset the slider---posts a changeme and will look weird in debug
$("#scaleslider").slider("value",300);

//removes the old one and highlighters

$('#faveP li').removeClass('ui-state-highlight');
$item.removeClass('ui-state-highlight');
$('#patternbox').removeClass('ui-state-highlight');


}
});
}



function loadTips(thistip,thistitle){

$("#tiptitle").html(thistitle);         
$("#tip1").load("http://www.alluminare.com/includes/rule2/tips.asp?step="+thistip).effect("highlight",{}, 2500).fadeIn('slow');
}

function loadReview(){
$("#tip-review-head").removeClass("hid");
$("#tip-review").load("http://www.alluminare.com/includes/allcomments_doorway.asp?showlink=0").hide().fadeIn('slow');
}


function help(){

$('.help').click(function() {
$("#ajaxDialog").dialog('open');
$("#ajaxDialog").load($(this).attr('helplink'));
});
}





function clickbutton(){
$('.not-selected-button').click(function(ev) {
var $item = $(this);
var thistype= $item.attr("mytype")
if ($item.parent().hasClass("ui-state-disabled"))
{
$('#nocan').dialog('open')
return false;
}
else if ($item.closest('table').hasClass("ui-state-disabled")) 
{
$('#nocan').dialog('open')
return false;
}

else
{
	$('.selected-button').addClass('hid');
	$('.not-selected-button').removeClass('hid');

	$item.addClass('hid');
        $item.next('div').removeClass('hid'); 
       
       	if (thistype=="stocked")
        {       
	faveStock($item.parent().attr("id"),'True');
	}
	else if (thistype=="trim")
	{
	faveTrim($item.parent().attr("id"),'True');
	}
	else if (thistype=="sus")
	{
	
	faveSus($item.parent().attr("id"),'True');
	
	}
	else if (thistype=="size")
		{
		faveSize($item.parent().attr("id"),'True');
		
	}
	else if (thistype=="thiswid")
	{
	faveWid($item.parent().attr("id"),'True');
	
	}
	else if (thistype=="diffuser")
		{
		faveDiff($item.parent().attr("id"),'True');
		
	}
	
};
});
}
 





//highlighters - call these on runtime
function makehover(){
$('.makehover').hover(function(){
$(this).addClass('ui-state-highlight');
}, function() {
$(this).removeClass('ui-state-highlight');
});
}







function hiliteP(){
$('#pgallery li').hover(function(){
$('#clickthis').addClass('ui-state-highlight');
$(this).addClass('ui-state-highlight');

}, function() {
$('#clickthis').removeClass('ui-state-highlight');
$(this).removeClass('ui-state-highlight');

});
};

function hilite(){
$('#gallery li').hover(function(){
$('#dragthis').addClass('ui-state-highlight');
$(this).addClass('ui-state-highlight');
}, function() {
$('#dragthis').removeClass('ui-state-highlight');
$(this).removeClass('ui-state-highlight');

});

};

//misc click and hover funcs

$('#zoomin').click(function(){
s7zoom.zoomIn();
return false;
});

$('#zoomout').click(function(){
javascript:s7zoom.zoomOut();
return false;
});

$('.roomview').click(function(ev) {
window.open('http://www.alluminare.com/zoomviewer.asp?showme=product&sku='+$('#sku').html());
});


$('#sample').click(function(ev) {
if ( $("#sku:contains('239;')").length ) { 

window.open('http://www.alluminare.com/strikeoff.asp?sku='+$('#sku').html());
}
else
{
window.open('http://www.alluminare.com/buysamples.asp?sku='+$('#sku').html());

}
});


function zoom(){
$('.zoom').click(function() {
var showme=$(this).attr('showme')
var showthis=$(this).attr('showthis')
$("#zoomDialog").dialog('open');
$("#zoomDialog").load('http://www.alluminare.com/zoomviewer-prod.asp?showme='+showme+'&sku='+showthis);
});
}

//adders

function addFaves(render){
faveImage2($(my1),$fave1,'custom_color1',render);
faveImage2($(my2),$fave2,'custom_color2',render);
faveImage2($(my3),$fave3,'custom_color3',render);
faveImage2($(my4),$fave4,'custom_color4',render);
}


function addTrim(){
if (document.getElementById("my31").innerHTML!='')
{
var $myid=$('#b1-'+document.getElementById("my31").innerHTML)
var $myid2=$('#b2-'+document.getElementById("my31").innerHTML)
 $myid.addClass('hid');
 $myid2.removeClass('hid');
}
else
{
 $('#b1-TNO').addClass('hid');
 $('#b2-TNO').removeClass('hid');

}


};



function addStock(){

if (stockedid=='')
{
//do nothing
}
else
{
faveStock($('#S'+stockedid).attr("id"),false);
var $myid=$('#b1-S'+stockedid)
var $myid2=$('#b2-S'+stockedid)
 $myid.addClass('hid');
 $myid2.removeClass('hid');
}
}



function addSizes(){
if ( $('#mysize').length )

{
var $myid=$('#b1-len'+document.getElementById("mysize").innerHTML)
var $myid2=$('#b2-len'+document.getElementById("mysize").innerHTML)
 $myid.addClass('hid');
 $myid2.removeClass('hid');
}

};


function addSus(){
if (document.getElementById("mysus").innerHTML!='')
{
var $myid=$('#b1-'+document.getElementById("mysus").innerHTML)
var $myid2=$('#b2-'+document.getElementById("mysus").innerHTML)
 $myid.addClass('hid');
 $myid2.removeClass('hid');
}

};

function addDiff(){
if (document.getElementById("mydiff").innerHTML!='')
{
var $myid=$('#b1-'+document.getElementById("mydiff").innerHTML)
var $myid2=$('#b2-'+document.getElementById("mydiff").innerHTML)
 $myid.addClass('hid');
 $myid2.removeClass('hid');
}

};

function addWid(){
if (document.getElementById("mywid").innerHTML!='')
{
var $myid=$('#b1-'+document.getElementById("mywid").innerHTML)
var $myid2=$('#b2-'+document.getElementById("mywid").innerHTML)
 $myid.addClass('hid');
 $myid2.removeClass('hid');
}

};






///run defaults
delthis();
makehover();

clickbutton();
help();
$("table.buy tr:even").addClass("hirow");





if (pagetype=="lighting"){

if (currentstep=="1")
{
  if (substep.length)
  {
	  if (substep=="1")
	  {	
	  loadPat();
	  loadColors();
	  }
	  else
	  {
	  loadStocked();
	  }
  
  }
  else
  {
  	  if (showcustom=="1")
  	  {
  	  loadColors();
  	  loadPat();
  	  }
  	  else
  	  {
  	  loadStocked();
	  }
  
  
  }


}


if (currentstep=="2")
{
loadWid();
}

if (currentstep=="3")
{
addSizes();
loadTips(pagetype+"-h-default");
loadReview();

}


if (currentstep=="4")
{
loadTrim();
}

if (currentstep=="5")
{
loadSus();
}


if (currentstep=="6")
{
addDiff();
loadTips(pagetype+"-d-default");
loadReview();

}
};



///shades

if (pagetype=="shades"){

if (currentstep=="1")
{
  if (substep.length)
  {
	  if (substep=="1")
	  {	
	  loadPat();
	  loadColors();
	  }
	  else
	  {
	  loadStocked();
	  }
  
  }
  else
  {
  	  if (showcustom=="1")
  	  {
  	  loadColors();
  	  loadPat();
  	  }
  	  else
  	  {
  	  loadStocked();
	  }
  
  
  }


}


if (currentstep=="2")
{
loadWid();
}

if (currentstep=="3")
{
addSizes();
loadTips(pagetype+"-h-default");
loadReview();

}


if (currentstep=="4")
{
loadTrim();
}


};
//
///pillows

if (pagetype=="pillow"){

if (currentstep=="1")
{
 	  loadPat();
	  loadColors();
	  

}
if (currentstep=="2")
{
addSizes();
loadTips(pagetype+"-h-default");
loadReview();

}
};
//
///wallpaper/fabric

if (pagetype=="wallpaper"||pagetype=="custom-fabric"){

if (currentstep=="1")
{
 	  loadPat();
	  loadColors();
	  

}
if (currentstep=="2")
{
addSizes();
loadTips(pagetype+"-h-default");

}
};
//
});


    			
