/*
6356319	Adult 24" x 12" x 3"
6356355	Adult 24" x 12" x 4"
6356384	Infant 18" x 10" x 4"
*/
var conf = {
	// vars
	TextSeparator : '|',
	// stone size settings and methods
	stonesize			: '',
	stonesizes		: ["~", "6356319", "6356355", "6356384"],
	// sizes, adult or infant
	setStoneSize	: function(val) { this.stonesize = this.stonesizes[val]; $("#hosted_button_id").val(this.stonesizes[val]); },
	stonecolor 		: '',
	// color of stone
	stonecolors		: {"A" : "Antique Gray", "B" : "Dusty Rose", "C" : "Midnight Black"},
	setStoneColor : function(val) { this.stonecolor = val; $("#os0").val(this.stonecolors[val]); },
	// logo
	setDesign 		: function(val) { $("#os1").val("Design " + val); },
	setTextLayout : function(val) { $("#os2").val(val); },
	setFont 			: function(val) { $("#os3").val(val); },
	setTextFields : function() { $("#os5").val( $("#text").val()); $("#os4").val($("#text2").val() + this.TextSeparator + $("#text3").val()); },
	//pricing				: {"A6356319" : 309, "A6356355" : 359, "B6356355" : 379, "C6356355" : 399, "A6356384" : 309, "B6356384" : 329, "C6356384" : 349},
	pricing				: {"A6356319" : 395, "A6356355" : 405, "B6356355" : 550, "C6356355" : 495, "A6356384" : 365, "B6356384" : 495, "C6356384" : 445},
	setPricing		: function () {$("#price").html("$" + this.pricing[this.stonecolor + this.stonesize]); },
	stoneconfig : 1
}

cMarker = "A"
cLogo = "A"

mPath = "/images/Marker"
cPath = "/images/Logo"

// Rrefresh the Main Marker Image //
function refreshImage(){
	newStyle = new FLIRStyle({ cSize: $('#size').val() });
	$('#text-line-1').text($("#text").val()).removeClass('flir-replaced').removeAttr('flirReplaced').each(function(){ FLIR.replace(this, newStyle); });
	$('#text-line-2').text($("#text2").val()).removeClass('flir-replaced').removeAttr('flirReplaced').each(function(){ FLIR.replace(this, newStyle); });
	$('#text-line-3').text($("#text3").val()).removeClass('flir-replaced').removeAttr('flirReplaced').each(function(){ FLIR.replace(this, newStyle); });
	conf.setPricing();	
}

// Build the Main Marker Image //
function Change_Set(cItem,cColor,id){
	if (cItem == "Marker"){
conf.marker = cColor;
		conf.setStoneColor(cColor);
		cMarker = cColor;
		$('#color-list li').removeClass('active');
		$('#'+ id).addClass('active');
		if (cMarker == "C"){
			$('#text-holder div').addClass('white');
		}
		else {
			$('#text-holder div').removeClass('white');
		}
	}
	if (cItem == "Logo"){
conf.art = cColor;
		conf.setDesign(cColor);
		cLogo = cColor;
		$('.design-list li').removeClass('active');
		$('#'+ id).addClass('active');
	}
	refreshImage();
	document.colorset.src = mPath + cLogo + "_" + cMarker + ".jpg";
	return void(0);
}

// Generic Configuration Change functions //
function Change_Configuration1(){
conf.stoneconfig = 1;
	$('#text-holder').removeClass('config-2 config-3').addClass('config-1');
	Change_Set('Logo','A','logo-a');
	refreshImage();
}

function Change_Configuration2(){
conf.stoneconfig = 2;
	$('#text-holder').removeClass('config-1 config-3').addClass('config-2');
	Change_Set('Logo','J','logo-j')
	refreshImage();
}

function Change_Configuration3(){
conf.stoneconfig = 3;
	$('#text-holder').removeClass('config-1 config-2').addClass('config-3');
	refreshImage();
}	


// Click Functions //
$(function() { 
	$('#marker-a img').click(function(){
		Change_Set('Marker','A','marker-a');
		refreshImage();
	});

	$('#marker-b img').click(function(){
		Change_Set('Marker','B','marker-b');
		refreshImage();
	});

	$('#marker-c img').click(function(){
		Change_Set('Marker','C','marker-c');
		refreshImage();
	});
	
	// Stone Configuration Clicks -- Horizotal vs. Vertical layout //
	$('#config-1').click(function(){ Change_Configuration1(); });
	$('#config-2').click(function(){ Change_Configuration2(); });
	$('#config-3').click(function(){ Change_Configuration3(); });
	
	// Stone Size Clicks -- Change the Stone Size & Type //
	$('#stonesize1').click(function(){
		$('#marker-b, #marker-c, #infant').hide(); $('#vertical, #horizontal').show(); $('#tabs').tabs('select',0);
		Change_Set('Marker','A','marker-a'); Change_Set('Logo','A','logo-a'); 
		Change_Configuration1(); 
		conf.setStoneSize(1);
		refreshImage();
	});
	$('#stonesize2').click(function(){
		$('#marker-b, #marker-c, #vertical, #horizontal').show(); $('#infant').hide(); $('#tabs').tabs('select',0);
		Change_Set('Marker','A','marker-a'); Change_Set('Logo','A','logo-a'); 
		Change_Configuration1();
		conf.setStoneSize(2);
		refreshImage();
	});
	$('#stonesize3').click(function(){
		$('#marker-b, #marker-c, #infant').show(); $('#vertical, #horizontal').hide(); $('#tabs').tabs('select',2);
		Change_Set('Marker','A','marker-a'); Change_Set('Logo','S','logo-s'); 
		Change_Configuration3();
		conf.setStoneSize(3);
		refreshImage();
	});

	// Layout Clicks -- Change the layout of the Text //
	$('#layout1').click(function(){
		$('#text-holder > div').removeClass('layout-2').addClass('layout-1');
		conf.setTextLayout("Layout 1");
		refreshImage();
	});
	$('#layout2').click(function(){
		$('#text-holder > div').removeClass('layout-1').addClass('layout-2');
		conf.setTextLayout("Layout 2");
		refreshImage();
	});
	
	// Font Clicks -- Change the Font of the stone //
	$('#zurich').click(function(){
		$('#text-holder > div').removeClass('times-font optima-font').addClass('zurich-font');
		conf.setFont("Zurich");
		refreshImage();
	});
	$('#optima').click(function(){
		$('#text-holder > div').removeClass('times-font zurich-font').addClass('optima-font');
		conf.setFont("Optima");
		refreshImage();
	});
	$('#customtimes').click(function(){
		$('#text-holder > div').removeClass('optima-font zurich-font').addClass('times-font');
		conf.setFont("Times");
		refreshImage();
	});
	
	// Generic Refresh Image //
	$('.fire').click(function(){
		refreshImage();
		conf.setTextFields();
		 return false;
	 });

$("#preview").click(function() {
var font = $("input:checked[name=font]").attr('id');
font = font == 'customtimes' ? 'times' : font;
var marker = conf.marker;
var art = conf.art;
var layout = $("input:checked[name=Layout1]").attr('id') == 'layout1' ? 1 : 2;
var t1 = $("#text").val();
var t2 = $("#text2").val();
var t3 = $("#text3").val();
var stoneconfig = $("input:checked[name=StoneSize]").val() == 'Infant' ? 3 : conf.stoneconfig;
var params = '?t1=' + escape(t1) + '&t2=' + escape(t2) + '&t3=' + t3 + '&font=' + escape(font) + '&art=' + escape(art.toLowerCase()) + '&marker=' + escape(marker.toLowerCase()) + '&config=' + escape(layout) + '&stonesize=' + stoneconfig + '&popup=image';
//alert(params);
var imagepreview = window.open ("http://www.qualitymarkers.com/image.php" + params, "imagepreview", "onClick=javascript: pageTracker._trackPageview('/print/marker');,menubar=1,resizable=1,width=650,height=350");
imagepreview.focus();

});

	// initialize function
	 setTimeout(function() {
			try{if(getQStr('popup')){ return false;}}catch(e){}
			var c = getQStr('c')+"";
			c = (c == 'undefined') ? 2 : c;
			switch(c) {
				case 3:
					var p2 = 'S'; var p3 = 's';
					break;
				case 1:
				case 2:
				default:
					var p2 = 'A'; var p3 = 'a';
			}
			$("#stonesize" + c + ", #marker-a, #customtimes, #layout1, .fire").trigger('click');
			Change_Set('Logo',p2,'logo-' + p3);
			$("#stonesize" + c).trigger('click');
		}, 500);
});

/**
 * get query string variable value
 * @param variable the variable to retrieve
 * @return the value of the query string variable
 */
function getQStr(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}


