window.addEvent('domready', function() {
	homeSplash();
	accordion();
	logOut();
	cvdTip();
	popFlashworld();
	print();
	wmTipz();
	invoiceOpen();
	openActivation();
});

function homeSplash(){
	var splash = document.id('homeFlash_splash');
	if (splash) {

		var autoSwfObject = new AutoSwiff('images/splash.swf', {
			container :splash,
			width :635,
			height :374,
			params :{
				wmode :'opaque'
			},
			vars :{
				expressinstall :"images/expressInstall.swf",
				version :"10"
			}
		});

	}
}

function openFlashworld(newAccount) {
	var uri = '/flashworld.php';
	if (newAccount == 'newAccount') {
		uri += '?makeNewAccount=true';
	}
	window
			.open(
					uri,
					"flashworldWindow",
					"height="
							+ screen.height
							+ ",width="
							+ screen.width
							+ ",left=0,top=0,status=0,location=0,menubar=0,scrollbars=0,titlebar=0,toolbar=0,directories=0");
}

function popFlashworld() {
	$$('a.swfWorld').addEvent('click', function(e) {
		e.stop();
		var newAccount = this.get('rel');
		openFlashworld(newAccount);
	});
}

function logOut() {
	$$('div.logout').addEvent('click', function(e) {
		var ajx = new Request({
			'url' : 'ajx/logout.ajx.php?ajx=true',
			onComplete : function() {
				location.href = './';
			}
		}).send();
	});
}

function accordion() {
	var blocks = $$('div.zagl');
	blocks.each(function(el) {
		var toggler = el.getElement('a.toggler');
		if (toggler) {
			toggler.addEvent('click',
					function(e) {
						e.stop();
						var display = el.getElement('div.showbody').getStyle(
								'display');

						if (display == 'block') {
							el.set('class', 'zagl hide');
							this.getElement('img').set('src',
									'images/view2_btn.gif');
							el.getElement('div.showbody').setStyle('display',
									'none');
						} else {
							el.set('class', 'zagl show');
							this.getElement('img').set('src',
									'images/hide_btn.gif');
							el.getElement('div.showbody').setStyle('display',
									'block');
						}

					});
		}
	});
}

function ajx_loading(el) {
	if (document.id('ajx_loading')) {
		return;
	}
	var target = el.getParent();
	var loading = new Element('div', {
		'id' : 'ajx_loading'
	});
	loading.set('opacity', 0.50);
	loading.inject(target, 'top');
}

function remove_ajx_loading() {
	if (!document.id('ajx_loading')) {
		return;
	}
	document.id('ajx_loading').destroy();
}

function pastText(id,value){
 
 SelectedOption = form.ManageAccount.selProvId;
 // $('#'+id).html(value);
 alert(SelectedOption);
}

function cvdTip() {
    $$('.cvd').each( function(itm, ind) {
	var content = itm.get('title').split('::');
	itm.store('tip:title', content[0]);
	itm.store('tip:text', content[1]);
    });

    var tipz = new Tips('.cvd', {
	className :'cvdTip',
	fixed :false,
	hideDelay :50,
	showDelay :50
    });
    
}

function wmTipz() {
    $$('.wmTipz').each( function(itm, ind) {
	var content = itm.get('title').split('::');
	itm.store('tip:title', content[0]);
	itm.store('tip:text', content[1]);
    });

    var tipz = new Tips('.wmTipz', {
	className :'wmTip',
	fixed :false,
	hideDelay :50,
	showDelay :50
    });
    
}

function invoiceOpen(){
	var invOpen = document.id('inv_open');
	if(!invOpen){
		return false;
	}
	var container = document.id('orders_container');
	container.setStyle('display','none');
	
	invOpen.addEvent('click',function(){
		
		var src = this.get('src');
		
		if(src.indexOf('open')> -1){
			src = src.replace('open','close');
			container.setStyle('display','block');
		}else if(src.indexOf('close')> -1){
			src = src.replace('close','open');
			container.setStyle('display','none');
		}
		this.set('src',src);
	});
}

function print() {
	$$('a[rel=print]').addEvent('click', function(e) {
				e.stop();
				var str = this.get('href');
				var str = str.split('/');
				var refNum = str.getLast();
				if(refNum == ''){
					refNum = str[str.length-2];
				}
				
				var lnk = './views/muvStore_invoice.php?refnum='+refNum;
				
				window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,width=905');
			});
}

function openActivation(){
	var actOpen = document.id('activationOpen');
	if(!actOpen){
		return false;
	}
	var container = document.id('activation_container');
	container.setStyle('display','none');
	
	actOpen.addEvent('click',function(){
		
		var src = this.get('src');
		
		if(src.indexOf('open')> -1){
			src = src.replace('open','close');
			container.setStyle('display','block');
		}else if(src.indexOf('close')> -1){
			src = src.replace('close','open');
			container.setStyle('display','none');
		}
		this.set('src',src);
	});
}


var AutoSwiff = new Class({

	Extends :Swiff,

	initialize : function(path, options) {

		if (Browser.Plugins.Flash.version > 0) {
			this.parent(path, options);
			this.versionCheck(Browser.Plugins.Flash);
		} else {
			Utils.showAllFlashAltContent(true);
		}

	},

	versionCheck : function() {

		var flashVersion = this.options.vars.version;

		if (Browser.Plugins.Flash.version < flashVersion) {

			var origSwf = this;

			var installSwf = new Swiff(origSwf.options.vars.expressinstall, {
				container :origSwf.options.container,
				width :origSwf.options.width,
				height :origSwf.options.height,

				params :{},

				vars :{}

			});

		}

	}

});
