/**
 * @author George Miller
 */
Ext.onReady(function(){
//initalize the quicktips
Ext.QuickTips.init();
//reference the default image
Ext.BLANK_IMAGE_URL = 'ext-2.1/resources/images/default/s.gif';


function createTutorialWindow(){
		var check = Ext.getCmp('tutwindow');
	if(!check){
		
	var mConfig = {
                   mediaType  :'WMV'
                  ,url        :'http://www.casinotools.co.uk/images/CasinoToolsTutorial-Final.wmv'
                  ,autoSize  : true
                  ,id         :'tutmovie'
                  ,unsupportedText : 'Please download the Windows Media Player plugin'
                  ,controls   :true
                  ,start      :true}; 
                  
        var tutwindow = new Ext.ux.MediaWindow ({id:'movieTut'
                            ,height     : 508
                            ,width      : 655
                            ,title: 'Casino Tools Tutorial'
                            ,iconCls: 'movie'
                            ,resizable : false
                            ,collapsible:false
                            ,constrain: true
                            ,mediaCfg   : mConfig
                            ,autoScroll : false  //dont want scroll bars around it.
                            }); 
	}
	tutwindow.show();

}
Ext.get('tutorial_img').on('click', function(){
createTutorialWindow()
});
Ext.get('tutTop').on('click', function(){
createTutorialWindow()
});
Ext.get('tutBtm').on('click', function(){
createTutorialWindow()
});

function createAdvertWindow(){
		var check = Ext.getCmp('adwindow');
	if(!check){
		
		var mConfigAd = {
                   mediaType  :'WMV'
                  ,url        :'http://www.casinotools.co.uk/images/CasinoToolsAdvert.wmv'
                  ,autoSize  : true
                  ,id         :'admovie'
                  ,unsupportedText : 'Please download the Windows Media Player plugin'
                  ,controls   :true
                  ,start      :true}; 
				  
		var adwindow = new Ext.ux.MediaWindow ({id:'movieAd'
                            ,height     : 508
                            ,width      : 655
							,title: 'Casino Tools Advert'
							,iconCls: 'movie'
                            ,resizable : false
                            ,collapsible:false
							,constrain: true
                            ,mediaCfg   : mConfigAd
                            ,autoScroll : false  //dont want scroll bars around it.
                            });
	}
	adwindow.show();

}
Ext.get('advert_img').on('click', function(){
createAdvertWindow()
});
Ext.get('adTop').on('click', function(){
createAdvertWindow()
});
Ext.get('adBtm').on('click', function(){
createAdvertWindow()
});

//tell friend bit
function submitForm(){
	var form = Ext.getCmp('emailform');
						
						if (form.form.isValid()) {
							Ext.MessageBox.show({
            title: 'Please wait',
           msg: 'Saving Edited Data...',
           progressText: 'Collecting items...',
           width:300,
           progress:true,
           closable:false
       });
							form.form.submit({
								params: {
									action: 'submit'
								},
								success: function(form, action){
									var name = action.result.name;
									var fr = action.result.friend;
									// this hideous block creates the bogus progress
									var f = function(v){
										return function(){
											if (v == 12) {
												Ext.MessageBox.hide();
												Ext.MessageBox.show({
							title: 'Successful Entry',
							width: 400,
							height: 200,
							msg: 'Thank you '+name+',<br>You have successfully sent your Tell A Friend email to '+fr+',<br>Thanks for spreading the word',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.INFO
						});
											}
											else {
												var i = v / 11;
												Ext.MessageBox.updateProgress(i, Math.round(100 * i) + '% completed');
											}
										};
									};
									for (var i = 1; i < 13; i++) {
										setTimeout(f(i), i * 200);
									}
							form.reset();
							friendwindow.close();
								},
								failure: function(form, action){
									if (action.result.errors.length > 0) {
										Ext.MessageBox.show({
							title: 'Error',
							width: 250,
							height: 150,
							msg: action.result.errors,
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.WARNING
						})
									}
								}
							});
						}
						else {
							Ext.MessageBox.show({
							title: 'Error',
							width: 250,
							height: 150,
							msg: 'Please correct indicated errors',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.WARNING
						})
						}
}

function createFriendWindow(){
		var check = Ext.getCmp('friendwindow');
	if(!check){
		var friendwindow = new Ext.Window({
				height: 330,
				width: 340,
				iconCls: 'email',
				constrain: true,
				resizable: false,
				id: 'friendwindow',
				bodyStyle: 'padding:5px 5px 0 5px;',
				layout: 'fit',
				title: 'Tell A Friend',
				items: [{
	xtype: 'form',
	id: 'emailform',
	layout: 'form',
	autoHeight: true,
    baseCls: 'x-plain',
	labelAlign: 'top',
	labelWidth: 200,
	frame: true,
	keys: {
        key: [10,13],
        fn: function(){ submitForm() }
    },
	defaultType: 'textfield',
	url: 'includes/friend_process.php',
	items: [{
		name: 'your_name',
		width: 250,
		allowBlank: false,
		fieldLabel: 'Your Name'
	},{
		name: 'your_email',
		width: 250,
		allowBlank: false,
		id: 'youremailbox',
		vtype: 'email',
		fieldLabel: 'Your Email Address'
	},{
		name: 'fr_name',
		width: 250,
		allowBlank: false,
		fieldLabel: 'Your Friend\'s Name'
	},{
		name: 'fr_email',
		width: 250,
		allowBlank: false,
		id: 'fremailbox',
		vtype: 'email',
		fieldLabel: 'Your Friend\'s Email Address'
	},{
		name: 'msg',
		width: 310,
		xtype: 'textarea',
		preventScrollbars: true,
		height: 35,
		fieldLabel: 'Add your comments (optional)',
		value: 'I thought you would interested in seeing this website - www.casinotools.co.uk',
		allowBlank: false
	}]
       ,buttons: [{
            text: 'Submit',
			handler: function(){
						submitForm();
					}
        },{
            text: 'Cancel',
			handler: function(){
				Ext.getCmp('emailform').getForm().reset();
			}
        }]	
}]
				});
	}
	friendwindow.show();
}
Ext.get('tellTop').on('click', function(){
createFriendWindow()
});
Ext.get('tellBtm').on('click', function(){
createFriendWindow()
});
Ext.get('TellFriend').on('click', function(){
createFriendWindow()
});

});


