/*
 * PureTrak Index Page Javascript File
 * Copyright(c) 2008-2009, Pure Voice Communictions, Inc.
 * http://www.puretrak.com
 * @author Patrick Hallinan
 *
 */
 
Ext.onReady(function() {
	// -- Enable quick tips - feedback for any errors
	Ext.QuickTips.init();
	
	var official_reviews_store = new Ext.data.Store({
		storeId		: 'official_reviews_store',
		autoLoad	: true,
		remoteSort	: true,
		proxy: new Ext.data.HttpProxy({
			url		: '/index/retrieve_official_reviews',
			method	: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			id				: 'review_id',
			root			: 'results',
			successProperty	: 'success',
			}, new Ext.data.Record.create([
				{name: 'review_id', type: 'int'},
				{name: 'review_title', type: 'string'},
				{name: 'review_description', type: 'string'},
				{name: 'review_url', type: 'string'},
				{name: 'review_published_date', type: 'date', dateFormat: 'Y-m-d'}
			])
		)
	});
	
	var official_reviews_tpl = new Ext.XTemplate(
		'<tpl for=".">',
		'	<div class="official_review_container">',
		'		<table id="table_review_info">',
		'			<tr>',
		'				<td><a href="{review_url}" target="_blank" class="title"><span class="review_title">{review_title}</span></a></td>',
		'			</tr>',
		'			<tr>',
		'				<td><span class="review_date">{[fm.date(values.review_published_date, "n/j/y")]}</td>',
		'			</tr>',
		'			<tr>',
		'				<td><div class="review_description">{review_description}</div><a href="{review_url}" target="_blank"><div class="review_url">Read More...</div></a></td>',
		'			</tr>',
		'			<tr>',
		'				<td><div class="review_divider"><img src="/assets/images/index/review_divider.png"></div></td>',
		'			</tr>',
		'		</table>',
		'	</div>',
		'</tpl>',
		'<div class="x-clear"></div>'
	);
	
	var official_reviews_panel = new Ext.Panel({
		autoWidth	: true,
		autoHeight	: true,
		frame		: false,
		border		: false,
		bodyStyle	: 'background:transparent;',
		renderTo	: 'product_reviews_main_container',
		items: new Ext.DataView({
			store	: official_reviews_store,
			tpl		: official_reviews_tpl,
			frame	: false,
			border	: false,
			itemSelector	:'div.official_review_container',
			emptyText		: 'No reviews to display.',
		})
	});
	
	
	

	var counter = 0;
	var init = 0;
	
	var index_main_banner_task = {
		run: function() {
			
			if(init == 0){
				init++;
			} else {
				var img_array = new Array(
					new Array('ad_perfect_glide.jpg', '/products'),
					new Array('ad_expose_true_talent.gif', '/products/item/6'),
					new Array('ad_complexity_pad.jpg', '/products/item/7'),
					new Array('ad_join_facebook.jpg', 'http://www.facebook.com/pages/PureTrak/202305725892')
				);
				
				var len = img_array.length;
	
				var el = Ext.get('main_ad_container');
				el.sequenceFx().fadeOut({
					easing:'easeOut',
					duration:1.2,
					remove:false,
					callback: function() {
						el.update('<a href="'+img_array[counter][1]+'"><img src="/assets/images/index_ads/'+img_array[counter][0]+'" /></a>')
					}
				}).fadeIn({duration: 1.2});
				counter++;
				if((counter % len) == 0) {
					counter = 0;
				}
			}
		},
		interval: 6000 // -- 6 seconds
	}
	
	Ext.TaskMgr.start(index_main_banner_task);

});