var businesscard = new Class({
    initialize: function(){
	
		flashMovie = $('mainMov');
		 ptrnMovie = $('ptrnMov');
		 bizcardcolor = $$('.color');
		 el=$('customFieldText');
		 el2=$('customFieldColor');
		
		$('tags').addEvent('keyup', function(e) {
			$('content_title').value = $('tags').value; 
		});
		
		$('sendptrn').addEvent('click', function(e) {
				changingImg("bgptrn",$('pattersend').value)
		});
	
        this.ambilFont('http://cardxc.com/business-card/fontset/');
		this.ambilPattern('http://cardxc.com/business-card/pattern/');
		this.ambilCorner('http://cardxc.com/business-card/corner/');
		this.ambilShape('http://cardxc.com/business-card/shape/');
		this.tabber();
		this.editText();
		this.controlMC();
    },
	
	tabber: function(){
		$('content1').addClass("activecontent");
		$('link1').addClass("activetab");
		
		
		
		$('link1').addEvent('click', function(event) {
			event = new Event(event).stop();
			$$('.content').removeClass("activecontent");
			$$('.tab').removeClass("activetab");
			$('content1').addClass("activecontent");
			$('link1').addClass("activetab");
		});
		$('link2').addEvent('click', function(event) {
			event = new Event(event).stop();
			$$('.content').removeClass("activecontent");
			$$('.tab').removeClass("activetab");
			$('content2').addClass("activecontent");
			$('link2').addClass("activetab");
		});
		$('link3').addEvent('click', function(event) {
			event = new Event(event).stop();
			$$('.content').removeClass("activecontent");
			$$('.tab').removeClass("activetab");
			$('content3').addClass("activecontent");
			$('link3').addClass("activetab");
		});
		$('link4').addEvent('click', function(event) {
			event = new Event(event).stop();
			$$('.content').removeClass("activecontent");
			$$('.tab').removeClass("activetab");
			$('content4').addClass("activecontent");
			$('link4').addClass("activetab");
		});
		$('link5').addEvent('click', function(event) {
			event = new Event(event).stop();
			$$('.content').removeClass("activecontent");
			$$('.tab').removeClass("activetab");
			$('content5').addClass("activecontent");
			$('link5').addClass("activetab");
		});
		$('link6').addEvent('click', function(event) {
			event = new Event(event).stop();
			$$('.content').removeClass("activecontent");
			$$('.tab').removeClass("activetab");
			$('content6').addClass("activecontent");
			$('link6').addClass("activetab");
		});
	},
	
	editText: function(){
		bizcardtext = $$('.bizcardtext');
		bizcardtext.each(function(mytext){
			mytext.addEvent('keyup', function(e) {
				if (bizcardtext[bizcardtext.indexOf(mytext)].value == "") {
				isitext = ".|.";
				}else {
				isitext = bizcardtext[bizcardtext.indexOf(mytext)].value;
				};
				flashMovie.updateText(isitext,bizcardtext.indexOf(mytext));
				el.value = bizcardtext[0].value+".|."+bizcardtext[1].value+".|."+bizcardtext[2].value+".|."+bizcardtext[3].value+".|."+bizcardtext[4].value+".|."+bizcardtext[5].value+".|."+bizcardtext[6].value+".|."+bizcardtext[7].value+".|."+bizcardtext[8].value+".|."+bizcardtext[9].value+".|."+bizcardtext[10].value;
			}.bind(this));
		}.bind(this));
	},
	
	controlMC: function(){
				
		var goleft = $$('.leftbutton');
		var gotop = $$('.topbutton');
		var goright = $$('.rightbutton');
		var gobottom = $$('.botbutton');
		var goccw = $$('.ccw');
		var gocw = $$('.cw');
		var gosmall = $$('.scaleoutbutton');
		var gobig = $$('.scaleinbutton');

		//untuk pattern
		var patccw = $$('.pccw');
		var patcw = $$('.pcw');
		var patscaleout= $$('.pscaleout');
		var patscalein = $$('.pscalein');
		var patalphaout= $$('.palphaout');
		var patalphain = $$('.palphain');
		
		patalphain.each(function(paalphain){
			paalphain.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                modPattern([patalphain.indexOf(paalphain)],'alp',2.5);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		patalphaout.each(function(paalphaout){
			paalphaout.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                modPattern([patalphaout.indexOf(paalphaout)],'alp',-2.5);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		patscalein.each(function(pascalein){
			pascalein.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                modPattern([patscalein.indexOf(pascalein)],'sca',5);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		patscaleout.each(function(pascaleout){
			pascaleout.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                modPattern([patscaleout.indexOf(pascaleout)],'sca',-5);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		patccw.each(function(paccw){
			paccw.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                modPattern([patccw.indexOf(paccw)],'rot',-2.5);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		patcw.each(function(pacw){
			pacw.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                modPattern([patcw.indexOf(pacw)],'rot',2.5);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		
		goleft.each(function(gleft){
			gleft.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displayTxt([goleft.indexOf(gleft)],-2,0);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		gotop.each(function(gtop){
			gtop.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displayTxt([gotop.indexOf(gtop)],0,-2);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		goright.each(function(gright){
			gright.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displayTxt([goright.indexOf(gright)],2,0);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		gobottom.each(function(gbottom){
			gbottom.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displayTxt([gobottom.indexOf(gbottom)],0,2);
				holdTimer = setTimeout(changeValue, 80);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		goccw.each(function(gccw){
			gccw.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displaytxtRot([goccw.indexOf(gccw)],-2.5);
				holdTimer = setTimeout(changeValue, 100);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		gocw.each(function(gcw){
			gcw.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displaytxtRot([gocw.indexOf(gcw)],2.5);
				holdTimer = setTimeout(changeValue, 100);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		gosmall.each(function(gsmall){
			gsmall.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displaytxtSec([gosmall.indexOf(gsmall)],-3);
				holdTimer = setTimeout(changeValue, 100);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));
		
		gobig.each(function(gbig){
			gbig.addEvent('mousedown', function(e) {
			var holdTimer;
			var changeValue = function(){
                displaytxtSec([gobig.indexOf(gbig)],3);
				holdTimer = setTimeout(changeValue, 100);
             }			
			 changeValue();
			 document.onmouseup = function(){
                                clearTimeout(holdTimer);
                        }
		}.bind(this));
		}.bind(this));	
	},
		
		
	ambilFont: function(loadcontent){
		this.contentFont = new Ajax(loadcontent, {
								method: 'get',
								onComplete:this.clickfont.bind(this)
							}).request();
		
	},
	
	clickfont: function(){	
		$('nestfont').setHTML(this.contentFont.response.text);
		var fonts = $$('#nestfont .ajaxcontent a');
		fonts.each(function(el){
			el.addEvent('click',function(e){
				if(e != undefined){
					new Event(e).stop();
					changingImg('chatext',fonts[fonts.indexOf(el)].toString());
				}
			}.bind(this));	
		}.bind(this));
	},
	
	ambilPattern: function(loadcontent){
		this.contentPattern = new Ajax(loadcontent, {
								method: 'get',
								onComplete:this.clickpattern.bind(this)
							}).request();
		
	},
	
	clickpattern: function(){	
		$('nestpattern').setHTML(this.contentPattern.response.text);
		var swfptrn = $$('#nestpattern .ajaxcontent a');
		//var swfptrn = $$('.ptrn');
		swfptrn.each(function(el){
			el.addEvent('click',function(e){
				if(e != undefined){
					new Event(e).stop();
					loadptrn(swfptrn[swfptrn.indexOf(el)].toString()+"?rot=0&mycolor=0x000000&myalpha=100&scale=100&rotSmall=0&mycolorSmall=0xCDCDCD&myalphaSmall=100&scaleSmall=100&bgColor=0xFFFFFF&loc="+swfptrn[swfptrn.indexOf(el)].toString());
				}
			}.bind(this));	
		}.bind(this));
	},
	
	ambilCorner: function(loadCorner){
		this.contentCorner = new Ajax(loadCorner, {
								method: 'get',
								onComplete:this.clickcorner.bind(this)
							}).request();
		
	},
	
	clickcorner: function(){	
		$('nestcorner').setHTML(this.contentCorner.response.text);
		var links = $$('#nestcorner .ajaxcontent a');
		links.each(function(el){
			el.addEvent('click',function(e){
				if(e != undefined){
					new Event(e).stop();
					changingImg('pattern',links[links.indexOf(el)].toString());
				}
			}.bind(this));	
		}.bind(this));
	},
	
	ambilShape: function(loadShape){
		this.contentShape = new Ajax(loadShape, {
								method: 'get',
								onComplete:this.clickShape.bind(this)
							}).request();
		
	},
	
	clickShape: function(){	
		$('nestshape').setHTML(this.contentShape.response.text);
		var shapes = $$('#nestshape .ajaxcontent a');
		shapes.each(function(el){
			el.addEvent('click',function(e){
				if(e != undefined){
					new Event(e).stop();
					changingImg('chashape',shapes[shapes.indexOf(el)].toString());
				}
			}.bind(this));	
		}.bind(this));
	},
	
});