window.addEvent('domready', function(){ 
	if($chk($('cart'))){$('cart').load('/new_cart.asp');}
	if ($chk($('framed-stage'))) var T=new ClickRotate({stage:'framed-stage',sliders:'framed-list',transition:'fade',gotoevent:'mouseenter',transitionduration:500,transitionlink:'ignore'});

	$$('.changeimage').each(function(elm){
		elm.setStyle('cursor','pointer');
		elm.addEvent('mouseenter',function(){
			$('theimage').src='/newfp/images/prices_images/'+this.getProperty('abbr');
		});
	});
	$$('a.targetblank').each(function(elm){
		elm.addEvent('click',function(e){
			e.stop();
			window.open(elm.getProperty('href'));
		});
	});
	
	if($chk($('hpfader'))){
		swfobject.embedSWF("http://www.canvasrus.co.uk/newfp/newfader.swf", "hpfader", "428", "285", "9.0.0");
	}

	
	if($chk($('convertprice'))){
		var convertto="mm";
		$('convertprice').addEvent('click',function(e){
			e.stop();
			$$('.sizeconvert').each(function(elm){
				if(convertto=='mm'){
					tmp = elm.get('text').replace(/"/g,'');
					tmp = tmp.split(' x ');
					w = Math.round(tmp[0].toInt()*2.5);
					h = Math.round(tmp[1].toInt()*2.5);
					elm.set('text',w+'cm x '+h+'cm');
					$$('.sizetitle').each(function(t){
						t.set('text','Size (Centimetres)');
					});
				}else{
					tmp = elm.get('text').split(' x ');
					w = Math.round(tmp[0].toInt()/2.5);
					h = Math.round(tmp[1].toInt()/2.5);
					elm.set('text',w+'" x '+h+'"');
					$$('.sizetitle').each(function(t){
						t.set('text','Size (Inches)');
					});
				}
			});
			if(convertto=='mm'){
				convertto = "inch";
				this.set('text','(convert to inches)');
			}else{
				convertto = "mm";
				this.set('text','(convert to cm)');
			}
		});
	}
	
	//Code for upload sizes
	$$('.viewsizes').each(function(elm){
		elm.addEvent('click',function(e){
			e.stop();
			$$('.viewsizes').each(function(elm2){ 
				$(elm2.getProperty('rel')).setStyle('display','none');	
				if(elm.getProperty('rel')==elm2.getProperty('rel')){
					elm2.setStyle('font-weight','bold');
				}else{
					elm2.setStyle('font-weight','normal');
				}
			});
			//Zero out the sizes on change
			//$$('.sizedropdown').each(function(elm2){ elm2.value='';});
			$(elm.getProperty('rel')).setStyle('display','block');
		});
	});
	
	$$('.multisquare').each(function(elm){
		var img = new Element('img',{
			'src':'/gfx/3square.gif',
			'styles':{
				'position':'absolute',
				'display':'none'
			}
		}).inject(elm);	
		elm.addEvent('mouseover',function(){
			img.setStyles({
				'left':this.getPosition().x+(this.getSize().x/2).toInt(),
				'top':(this.getPosition().y+this.getSize().y),
				'display':'block'
			});
		});
		elm.addEvent('mouseout',function(){img.setStyle('display','none');});
	});
	$$('.multisquareP').each(function(elm){
		var img = new Element('img',{
			'src':'/gfx/3squareP.gif',
			'styles':{
				'position':'absolute',
				'display':'none'
			}
		}).inject(elm);	
		elm.addEvent('mouseover',function(){
			img.setStyles({
				'left':this.getPosition().x+(this.getSize().x/2).toInt(),
				'top':(this.getPosition().y+this.getSize().y),
				'display':'block'
			});
		});
		elm.addEvent('mouseout',function(){img.setStyle('display','none');});
	});
	$$('.fivepanel').each(function(elm){
		var img = new Element('img',{
			'src':'/gfx/5rectangle.gif',
			'styles':{
				'position':'absolute',
				'display':'none'
			}
		}).inject(elm);	
		elm.addEvent('mouseover',function(){
			img.setStyles({
				'left':this.getPosition().x+(this.getSize().x/2).toInt(),
				'top':(this.getPosition().y+this.getSize().y),
				'display':'block'
			});
		});
		elm.addEvent('mouseout',function(){img.setStyle('display','none');});
	});
	$$('.foursquare').each(function(elm){
		var img = new Element('img',{
			'src':'/gfx/4square.gif',
			'styles':{
				'position':'absolute',
				'display':'none'
			}
		}).inject(elm);	
		elm.addEvent('mouseover',function(){
			img.setStyles({
				'left':this.getPosition().x+(this.getSize().x/2).toInt(),
				'top':(this.getPosition().y+this.getSize().y),
				'display':'block'
			});
		});
		elm.addEvent('mouseout',function(){img.setStyle('display','none');});
	});
	$$('.sixrec').each(function(elm){
		var img = new Element('img',{
			'src':'/gfx/6rec.gif',
			'styles':{
				'position':'absolute',
				'display':'none'
			}
		}).inject(elm);	
		elm.addEvent('mouseover',function(){
			img.setStyles({
				'left':this.getPosition().x+(this.getSize().x/2).toInt(),
				'top':(this.getPosition().y+this.getSize().y),
				'display':'block'
			});
		});
		elm.addEvent('mouseout',function(){img.setStyle('display','none');});
	});
	$$('.ninesquare').each(function(elm){
		var img = new Element('img',{
			'src':'/gfx/9square.gif',
			'styles':{
				'position':'absolute',
				'display':'none'
			}
		}).inject(elm);	
		elm.addEvent('mouseover',function(){
			img.setStyles({
				'left':this.getPosition().x+(this.getSize().x/2).toInt(),
				'top':(this.getPosition().y+this.getSize().y),
				'display':'block'
			});
		});
		elm.addEvent('mouseout',function(){img.setStyle('display','none');});
	});
	
	if($chk($('savecartbutton'))){
		$('savecartbutton').addEvent('click',function(){
			SaveCartOpen();
		});
	}
	
});

var ClickRotate = new Class({
	Implements: [Options],
	options: {
		stage: 'slider-stage',
		sliders: 'slider-list',
		gotoclass: 'gotolink',
		gotoevent:'click',
		next:'next',
		nextevent:'click',
		transition:'scroll',
		transitionduration:500,
		previous:'previous',
		previousevent:'click',
		autorotate:true,
		waittime:5000,
		returnrotate:true,
		returnafter:5000,
		returnid:null,
		intervalID:null
	},
	initialize: function(options) {
		this.setOptions(options);
		var op = this.options;
		var f = this;
		op.children = $(op.sliders).getChildren('li');
		if (op.transition == "fade"){
			var startloop = 1000+op.children.length;
			for(i=0;i<op.children.length;i++){
				op.children[i].setStyle("z-index",startloop);
				startloop--;
			}
		}
		
		if(op.autorotate) op.intervalID = this.autorotate.periodical(op.waittime,this);
		if($type($(op.next))=='element'){
			$(op.next).addEvent(op.nextevent,function(e){
				e.stop();
				if($type(op.returnid)=='number') $clear(op.returnid);
				if($type(op.intervalID)=='number'){
					$clear(op.intervalID);
					if(op.returnrotate) op.returnid = f.autorotate.delay(op.returnafter,f);
				}
				var children = $(op.sliders).getChildren('li');
				if (op.transition == "fade"){
					children[0].set('tween',{duration:op.transitionduration,onComplete:function(){
						children[0].setStyle("z-index",0).inject($(op.sliders)).setStyle('opacity',1);
						var children2 = $(op.sliders).getChildren('li');
						var startloop = 1000+op.children.length;
						for(i=0;i<children2.length;i++){
							children2[i].setStyle("z-index",startloop);
							startloop--;
						}
					}});
					children[0].tween('opacity', 0);
				}else{
					children[0].set('tween',{duration:op.transitionduration,onComplete:function(){children[0].inject($(op.sliders)).setStyle('margin-left',0);}});
					children[0].tween('margin-left', -children[0].getSize().x);
				}
			});
		}
		if($type($(op.previous))=='element'){
			$(op.previous).addEvent(op.previousevent,function(e){
				e.stop();
				if($type(op.returnid)=='number') $clear(op.returnid);
				if($type(op.intervalID)=='number'){
					$clear(op.intervalID);
					if(op.returnrotate) op.returnid = f.autorotate.delay(op.returnafter,f);
				}
				var children = $(op.sliders).getChildren('li');
				var last = children.length-1;
				if (op.transition == "fade"){
					children[last].set('tween',{duration:op.transitionduration,onComplete:function(){children[last].setStyle('opacity',1);}});
					children[last].setStyle('opacity',0).inject($(op.sliders),'top');
					var children2 = $(op.sliders).getChildren('li');
					var startloop = 1000+op.children.length;
					for(i=0;i<children2.length;i++){
						children2[i].setStyle("z-index",startloop);
						startloop--;
					}
					children[last].tween('opacity', 1);
				}else{
					children[last].set('tween',{duration:op.transitionduration,onComplete:function(){children[last].set('style','');}});
					children[last].setStyle('margin-left',-children[last].getSize().x).inject($(op.sliders),'top');
					children[last].tween('margin-left', 0);
				}
			});
		}
		$$("a."+op.gotoclass).each(function(elm){
			var slideid = elm.getProperty('rel');
			if ($type(slideid)=="string"){
				slideid=slideid.toInt();
				elm.addEvent(op.gotoevent,function(e){
					e.stop();
					if($type(op.returnid)=='number') $clear(op.returnid);
					if($type(op.intervalID)=='number'){
						$clear(op.intervalID);
						if(op.returnrotate) op.returnid = f.autorotate.delay(op.returnafter,f);
					}
					var children = $(op.sliders).getChildren('li');
					if (op.transition == "fade"){
						op.children[slideid].set('tween',{duration:op.transitionduration,onComplete:function(){
								op.children[slideid].setStyle('opacity',1);
								for(i=slideid+1;i<op.children.length;i++) op.children[i].inject($(op.sliders),'bottom');
								for(i=0;i<slideid;i++) op.children[i].inject($(op.sliders),'bottom');
								var children2 = $(op.sliders).getChildren('li');
								var startloop = 1000+op.children.length;
								for(i=0;i<children2.length;i++){
									children2[i].setStyle("z-index",startloop);
									startloop--;
								}
						}});
						op.children[slideid].setStyle('opacity',0).inject($(op.sliders),'top');
						var children2 = $(op.sliders).getChildren('li');
						var startloop = 1000+op.children.length;
						for(i=0;i<children2.length;i++){
							children2[i].setStyle("z-index",startloop);
							startloop--;
						}
						op.children[slideid].tween('opacity', 1);
					}else{
						op.children[slideid].set('tween',{duration:op.transitionduration,onComplete:function(){
							op.children[slideid].set('style','');
							for(i=slideid+1;i<op.children.length;i++) op.children[i].inject($(op.sliders),'bottom');
							for(i=0;i<slideid;i++) op.children[i].inject($(op.sliders),'bottom');
						}});
						op.children[slideid].setStyle('margin-left',-op.children[slideid].getSize().x).inject($(op.sliders),'top');
						op.children[slideid].tween('margin-left', 0);
					}
				});
			}

		
		});
		
	},
	autorotate:function(){
		var op = this.options;
		if($type(op.returnid)=='number'){
			$clear(op.returnid);
			op.returnid=null;
			op.intervalID = this.autorotate.periodical(op.waittime,this);
		}
		var children = $(op.sliders).getChildren('li');
		if (op.transition == "fade"){
			children[0].set('tween',{duration:op.transitionduration,onComplete:function(){
				children[0].setStyle("z-index",0).inject($(op.sliders)).setStyle('opacity',1);
				var children2 = $(op.sliders).getChildren('li');
				var startloop = 1000+op.children.length;
				for(i=0;i<children2.length;i++){
					children2[i].setStyle("z-index",startloop);
					startloop--;
				}
			}});
			children[0].tween('opacity', 0);
		}else{
			children[0].set('tween',{duration:op.transitionduration,onComplete:function(){children[0].inject($(op.sliders)).setStyle('margin-left',0);}});
			children[0].tween('margin-left', -children[0].getSize().x);
		}
	}
		
	
});


function SaveCartOpen(){
	var background = new Element('div', {'id':'scback','class':'savecartbackground','styles':{
		'width':'100%','height':window.getScrollSize().y}
	}).inject($(document.body));
	var forground = new Element('div', {'id':'scfore','class':'savecartforground'}).inject($(document.body));
	forground.setStyles({'top':(window.getSize().y/2)-(forground.getSize().y/2),'left':(window.getSize().x/2)-(forground.getSize().x/2)});
			
	var formtop = new Element('div',{'class':'savecarttop'}).inject(forground);
	var formcontainer = new Element('div',{'class':'savecartform'}).inject(forground);
	var formbottom = new Element('div',{'class':'savecartbottom'}).inject(forground);
	formcontainer.load('process/savecartform.asp');
}
