/*
	SITE PLATFORM v1.3
	built by AntalMedia (www.antalmedia.com)
	built on Mootools v1.11 (http://www.mootools.net)
	
	copyright 2007. all rights reserved.
	
	HOW TO ADD TO THE SITE OBJECT
	Object.extend(Site, {
		added_function: function() {
			alert('added');
		}
	});
		
*/
var filterURL = '';
var productCode = 0;
var Site = {
	
	start: function() {
		
		if($('outter_wrapper').getElementById('product_images')) {
			Site.loadFlash();
		}
		Site.formFields();
		if(Cookie.get('col_width')) {
			Site.changeWidth(Cookie.get('col_width'));
		}
		if(Cookie.get('font_size')) {
			Site.changeFontSize(Cookie.get('font_size'));
		}
	},
	loadFlash: function () {
		
		var flashcheckObj = new SWFObject("", "check", "", "", "9", "#FFFFFF", true);
		if(flashcheckObj.installedVer.major >= "9") {
			
			flashHeaderObj = new SWFObject("/lib/swf/" + parent_name + "/" + page_base_name + ".swf", "index_page", "488px", "335px", 9, "#FFFFFF", true);

			flashHeaderObj.addParam("wmode", "transparent");
			flashHeaderObj.addParam("salign", "tl");
			flashHeaderObj.addVariable("page_base_name", page_base_name);
			flashHeaderObj.addVariable("parent_name", parent_name);
			/*flashHeaderObj.addVariable("base_url", base_url);
			flashHeaderObj.addVariable("imageArray", imageArray.join(','));
			flashHeaderObj.addVariable("jsRandom", jsRandom);
			flashHeaderObj.addVariable("autoplaying", 'true');
			flashHeaderObj.addVariable("autoPlayTime", '7');
			flashHeaderObj.addVariable("randomPlay", 'false');
			flashHeaderObj.addVariable("fadeTime", '3');*/
			flashHeaderObj.write("product_images");
		}
		//
	},
	changeFontSize: function(fontSize) {
		
		var fontSizes = {'small':{'font-size' : '.8em' , 'line-height' : '1.1em'},'default':{'font-size' : '1em' , 'line-height' : '1.2em'}, 'large':{'font-size' : '1.2em' , 'line-height' : '1.4em'}};
		
		var fontArray = ['#col_c'];
		fontArray.each(function(font) {
			var currFontSize = $$(font).getStyle('font-size');
			var currLineHeight = $$(font).getStyle('line-height');
			$$(font).setStyles({'font-size': fontSizes[fontSize]['font-size'], 'line-height': fontSizes[fontSize]['line-height']});
		});
		
		Cookie.remove('font_size');
		Cookie.set('font_size', fontSize, {path: '/'});
		
		
	},
	formFields: function() {
		//contact form
		$$("input[type='text']").each(function(input){
			var defaultValue = input.alt;
			input.value = defaultValue;
			inputClass = input.getProperty("class");
			input.addEvents({
				focus : function(){
					var inputValue = this.value;
					var valueLength = inputValue.length;
					this.value = (valueLength < 1 || inputValue == defaultValue) ? "" : inputValue;
					this.addClass(inputClass+'_active');
				},
				blur : function(){
					var inputValue = this.value;
					var valueLength = inputValue.length;
					this.value = (valueLength < 1 || inputValue == defaultValue) ? defaultValue : inputValue;
					this.removeClass(inputClass+'_active');
				}
			});
		});
		//any others
	},
	buyNow: function() {
		if ( filterURL.length > 0 ) {
			//window.location = 'http://www.billetanything.com/' + filterURL;
			Site.openBrWindow( 'http://www.billetanything.com/' + filterURL, '', '' );
		} else if ( productCode != 0 ) {
			//window.location = 'http://www.billetanything.com/' + page_base_name + '-p/' + productCode + '.htm';
			Site.openBrWindow( 'http://www.billetanything.com/' + page_base_name + '-p/' + productCode + '.htm', '', '' );
		} else {
			//window.location = 'http://www.billetanything.com/' + parent_name + '-s/' + category_id + '.htm';
			Site.openBrWindow( 'http://www.billetanything.com/' + parent_name + '-s/' + category_id + '.htm', '', '' );
		}
	},
	bookmarkPage: function() {
		if ( browser == 'Microsoft Internet Explorer' && browser_version > 3) {
			window.external.AddFavorite(window.location,'Billet Anything');
		} else {
			alert('Please press ctrl + D to bookmark this page.');
		}
	}, openBrWindow: function (theURL,winName,features) {
		window.open(theURL,winName,features);
	}
}

window.addEvent('domready', Site.start);