var photoviewer_properties = {next:"next", prev:"prev", close:"<div class='b_outer2'><div class='b4 closeIcon'></div></div>"};
function popup(url) {window.open(url, "name","height=550,width=750,left=30,top=30,location=no,resizable=yes,scrollbars=yes,toolbar=no,status=no");}
function move(url) {window.location = url;}

function form_submit(form_element, add_fields) {
	var form_element = $(form_element);
	if(!form_element) return false;
	if(add_fields) {
		for(key in add_fields) {
			new Insertion.Bottom(form_element,
				'<input type="hidden" name="' + key + '" value="' + add_fields[key] + '" />'
			);
		}
	}
	return form_element.submit();
}

function toggleOver(element_id, class_name) {
	$(element_id).className = class_name;
}

function search_onfocus(element, default_text) {
	if ($(element).value == default_text) {
		$(element).value = "";
	}
	$(element).style.color = "#000";
}

function search_onblur(element, default_text) {
	$(element).value = default_text;
	$(element).style.color = "#ccc";
}

function search_close(element, default_text, target) {
	search_onblur(element, default_text);
}

function showException(originalRequest, exception) {
	log_error("ajax exception: " + exception,'','');
}

function add_favorite_design(design_id, url) {
	var params = "add=1&design_id=" + design_id;
	new Ajax.Request(url, {
		method: 'post'
		,parameters: params
		,onComplete: function (originalRequest, json) {
			$('button_fav_' + design_id).className = "button_favorite";
			$('button_fav_' + design_id).title = originalRequest.responseText;
		}
		,onException: showException
	});
}

function remove_favorite_design(design_id, url) {
	var params = "remove=1&design_id=" + design_id;
	new Ajax.Request(url, {
		method: 'post'
		,parameters: params
		,onComplete: function (originalRequest, json) {
			$('button_fav_' + design_id).className = "button_favorite_add";
			$('button_fav_' + design_id).title = originalRequest.responseText;
		}
		,onException: showException
	});
}

function toggle_favorite_design(design_id, url) {
	if ($('button_fav_' + design_id).className.substring(0, 19) == 'button_favorite_add') {
		return add_favorite_design(design_id, url);
	} else {
		return remove_favorite_design(design_id, url);
	}
}

function hide_select_controls() {
	var elements = $$('SELECT'); if (elements) for(var i=0; i<elements.length; i++) $(elements[i]).style.display = 'none'; 
}

function show_select_controls() {
	var elements = $$('SELECT'); if (elements) for(var i=0; i<elements.length; i++) $(elements[i]).style.display = '';
}

function remind_me_design(design_id, date, url, onComplete) {
	var params = "design_id=" + design_id + "&date[year]=" + date.year + "&date[month]=" + date.month + "&date[day]=" + date.day;
	new Ajax.Request(url, {
		method: 'post'
		,parameters: params
		,onComplete: onComplete
		,onException: showException
	});
}

function reorder_images(album_id, order_list, url, onComplete) {
	new Ajax.Request(url, {
		method: 'post'
		,postBody: "album_id=" + album_id + "&order=" + order_list.toJSON()
		,onComplete: onComplete
		,onException: showException
	});
}

function post_ajax_yui(postData, sUrl, onComplete) {
	var handleSuccess = onComplete;

	var handleFailure = function(o){
		YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");
	};

	var callback =
	{
		success:handleSuccess,
		failure: handleFailure
	};
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
}

function post_ajax(params, url, onComplete) {
	return new Ajax.Request(url, {
		method: 'post'
		,parameters: params
		,onComplete: onComplete
		,onException: showException
	});
}

function post_effects(image_id, params, url, onComplete) {
	var parameters = Object.toJSON(params);
	new Ajax.Request(url, {
		method: 'post'
		,postBody: "image_id=" + image_id + "&params=" + parameters
		,onComplete: onComplete
		,onException: showException
	});
}

function show_preview_image(src) {
	hide_select_controls();
	$('preview_image_big').src = src;
	$('preview_image_big_container').style.display = ''; 
	$('preview_image_big_container').scrollTo();
}
function hide_preview_image() {
	$('preview_image_big_container').style.display = 'none'; 
	$('preview_image_big').src = "http://c.optimalprint.com/img/loading-v1301032853.gif";
	show_select_controls();
}

var visible_price_list = false;
function show_price_list(id) {
	if (visible_price_list && $(visible_price_list)) {
		$(visible_price_list).style.display = 'none'; 
		visible_price_list = false;
	}
	if (id && $(id)) {
		$(id).style.display = ''; 
		visible_price_list = id;
	}
}
var visible_spec_list = false;
function show_spec_list(id) {
	if (visible_spec_list && $(visible_spec_list)) {
		$(visible_spec_list).style.display = 'none'; 
		visible_spec_list = false;
	}
	if (id && $(id)) {
		$(id).style.display = ''; 
		visible_spec_list = id;
	}
}

function is_email(email) {
	var regularExp = /^[0-9a-z_\-]+@[0-9a-z_\^\.\-]+\.[a-z]{2,3}$/i;
	return regularExp.test(email);
}

function window_stop(src) {
	try {
		if (document.all) {
			src.document.execCommand("Stop"); 	// If IE
		} else {
			src.window.stop();					// If no IE
		}
	} catch (ex) {
		if (typeof log_error == 'function') log_error(ex);
	}
}

/*YUI Begin*/
window.YAHOO && (function(){

	Y = YAHOO;
	YU = Y.util;
	YA = YU && YU.Anim;
	YD = YU && YU.Dom;
	YE = YU && YU.Event;
	YS = YU && YU.Selector;
	YC = YU && YU.Connect;
	YR = YU && YU.Region;

	YL = Y.lang;
	YJSON = YL && YL.JSON;

	var extend = function( o1, o2) {
		if ( o1 ) {
			for( var i in o2) {
				o1[i] = o2[i];
			}
		}
		return o1;
	}
	var stripTags = function(str) {
		return str.replace(/<\/?[^>]+>/gi, '');
	}
	var stripScripts =  function( str) {
		return this.replace(new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'img'), '');
	}
	var extractScripts = function() {
		var matchAll = new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'img');
		var matchOne = new RegExp('<script[^>]*>([\\S\\s]*?)<\/script>', 'im');
		var result = [];
		var res = (this.match(matchAll) || []);
		for( var i=0; i<res.length; i++) {
			result.push((res[i].match(matchOne) || ['', ''])[1]);
		}
		return result;
	}
	var evalScripts = function(str) {
		var scrs = extractScripts( str);
		for( var i=0; i<scrs.length; i++) {
			eval(scrs[i]);
		}
	}
	var addListenerLocal = function( eventName, handler, useCapture) {
			var useCapture = useCapture || false;
			YE.addListener( this, eventName, handler, useCapture);
			return this;
	}
	var YElement = {
		show : function() {
			YD.setStyle( this, "display", "");
			return this;
		},
		hide : function() {
			YD.setStyle( this, "display", "none");
			return this;
		},
		setStyle : function( property, value) {
			YD.setStyle( this, property, value);
			return this;
		},
		getStyle : function( property) {
			return YD.getStyle( this, property);
		},
		addListener : addListenerLocal,
		on : addListenerLocal,
		update : function(innerHTML) {
			if ( this.tagName ) {
				this.innerHTML = innerHTML;
			} else if( this.length ) {
				for( var i=0; i<this.length; i++) {
					Y$(this[i]).update( innerHTML);
				}
			}
			return this;
		},
		evalScripts : function() {
			if ( this.tagName ) {
				while( this.getElementsByTagName( "SCRIPT").length ) {
					eval( this.getElementsByTagName( "SCRIPT")[0].innerHTML);
					this.getElementsByTagName( "SCRIPT")[0].parentNode.removeChild( this.getElementsByTagName( "SCRIPT")[0]);
				}
			} else if( this.length ) {
				for( var i0=0; i0<this.length; i0++) {
					this.evalScripts();
				}
			}
			return this;
		},
		disable : function() {
			if ( this.tagName ) {
				if ( this.tagName.toLowerCase() == "form" ) {
					for( var i=0; i<this.elements.length; i++) {this.elements[i].disabled = true;}
				} else {
					this.disabled = true;
				}
			} else if( this.length ) {
				for( var i=0; i<this.length; i++) {Y$(this[i]).disable();}
			}
			return this;
		},
		enable : function() {
			if ( this.tagName ) {
				if ( this.tagName.toLowerCase() == "form" ) {
					for( var i=0; i<this.elements.length; i++) {this.elements[i].disabled = false;}
				} else {
					this.disabled = false;
				}
			} else if( this.length ) {
				for( var i=0; i<this.length; i++) {Y$(this[i]).enable();}
			}
			return this;
		},
		getWidth : function() {
			var region = YR.getRegion(this);
			return region["right"]-region["left"];
		},
		getHeight : function() {
			var region = YR.getRegion(this);
			return region["bottom"]-region["top"];
		},
		insertAfter : function(node) {
			if ( !node.tagName ) {
				var div = document.createElement( "div");
				div.innerHTML = node;
				node = Y$(div).down();
			}
			if ( this.tagName ) {
				node && YD.insertAfter( node, this);
			} else {
				if ( node ) {
					for( var i=0; i<this.length; i++) {
						YD.insertAfter( node, this);
						node = document.cloneNode( node, 1);
					}
				}
			}
			return this;
		},
		remove : function() {
			if ( this.tagName ) {
				this.parentNode.removeChild(this);
			} else {
				for( var i=0; i<this.length; i++) {
					this[i].parentNode.removeChild(this[i]);
				}
			}
			return this;
		},
		toggle : function(type) {
			YU.Effect.toggle( this, type);
			return this;
		},
		each : function(func) {
			if ( this.tagName ) {
				func(this);
			} else {
				for( var i=0; i<this.length; i++) {
					func(this[i]);
				}
			}
			return this;
		},
		replace : function( content) {
			if ( this.tagName ) {
				if ( content.tagName ) {
					this.parentNode.replaceChild( content, this);
				} else {
					var tmp = document.createElement("div");
					tmp.innerHTML = String(content);
					while( tmp.firstChild ) {
						this.parentNode.insertBefore( tmp.firstChild, this);
					}
					this.parentNode.removeChild(this);
				}
			} else if( this.length ) {
				var tmp = document.createElement("div");
				for( var i=0; i<this.length; i++) {
					if ( content.tagName ) {
						this[i].parentNode.replaceChild( content, this[i]);
					} else {
						tmp.innerHTML = String(content);
						while( tmp.firstChild ) {
							this[i].parentNode.insertBefore( tmp.firstChild, this[i]);
						}
						this[i].parentNode.removeChild(this[i]);
					}
				}
			}
			return this;
		},
		down: function() {
			var selector = arguments[0] || "*";
			if ( this.tagName ) {
				return extend( YS.query( selector, this)[arguments[1] || 0] || null, YElement);
			} else {
				var nodes = [];
				for( var i0=0; i0<this.length; i0++) {
					var childs = YS.query( selector, this[i0]);
					for( var i=0; i<childs.length; i++) {
						nodes.push( childs[i]);
					}
				}
				return extend( nodes[arguments[1] || 0] || null, YElement);
			}
		},
		up: function() {
			var selector = arguments[0] || "*";
			var nodes = [];
			if ( this.tagName ) {
				var o=this;
				do {
					o = o.parentNode;
					nodes.push( o);
				} while( o && o.parentNode && o.parentNode != o );
			} else {
				for( var i0=0; i0<this.length; i0++) {
					var o=this[i0];
					do {
						o = o.parentNode;
						nodes.push( o);
					} while( o && o.parentNode && o.parentNode != o );
				}
			}
			return extend( YS.filter( nodes, selector)[arguments[1] || 0] || null, YElement);
		},
		adjacent: function() {
			var selector = [].join.call( arguments, ",");
			var nodes = [];
			if ( this.tagName ) {
				var childs = this.parentNode.childNodes;
				for( var i=0; i<childs.length; i++) {
					if ( childs[i] != this ) {
						nodes.push( childs[i]);
					}
				}
			} else {
				for( var i0=0; i0<this.length; i0++) {
					var childs = this[i0].parentNode.childNodes;
					for( var i=0; i<childs.length; i++) {
						if ( childs[i] != this[i0] ) {
							nodes.push( childs[i]);
						}
					}
				}
			}
			return extend( YS.filter( nodes, selector), YElement);
		}
	};

	YU.Effect = {};
	YU.Effect.toggle = function( objs, type) {
		var objs = ( objs.tagName && [objs]) || objs;
		var type = type || "";
		switch( type ) {
			case 'blind': {
				for( var i=0; i<objs.length; i++) {
					if ( !(objs[i].EffectBlocked) ) {
						objs[i].EffectBlocked = 1;
						YU.Effect.blind( objs[i]);
					}
				}
				break;
			}
			default: {
				for( var i=0; i<objs.length; i++) {
					if ( !(objs[i].EffectBlocked) ) {
						YD.setStyle( objs[i], 'display', YD.getStyle( objs[i], 'display')=='none'?'':'none');
					}
				}
			}
		}
	}
	YU.Effect.blind = function( obj) {
		if ( YD.getStyle( obj, 'display') != 'none' ) {
			YD.setStyle( obj, 'overflow-y', 'hidden');
			var anim = new YA( obj, {height:{to:1}}, .5, YU.Easing.easeInStrong);
			anim.onComplete.subscribe( function(){
				YD.setStyle( obj, 'display', 'none');
				obj.EffectBlocked = 0;
			});
		} else {
			YD.setStyle( obj, 'overflow-y', 'hidden');
			YD.setStyle( obj, 'height', "1px");
			YD.setStyle( obj, 'display', '');
			var anim = new YA( obj, {height:{to:obj.scrollHeight}}, .5, YU.Easing.easeInStrong);
			anim.onComplete.subscribe( function(){
				YD.setStyle( obj, 'overflow-y', 'visible');
				YD.setStyle( obj, 'height', 'auto');
				obj.EffectBlocked = 0;
			});
		}
		anim.animate();
	}

	Y$ = function( id) {
		return extend( ( id.tagName && id ) || Y$$( "#".concat( id))[0] || null, YElement);
	}
	Y$$ = function( selector, root_node, first_only) {
		var root_node = root_node || null;
		var first_only = first_only || 0;
		var res = YS.query( selector, root_node, first_only);
		for( var i=0; i<res.length; i++) {
			extend( res[i], YElement);
		}
		return extend( res, YElement);
	}
	Y$A = function( collection) {
		return extend( collection, YElement);
	}
})();
/*YUI End*/


