/*
 * Metadata - jQuery plugin for parsing metadata from elements
 *
 * Copyright (c) 2006 John Resig, Yehuda Katz, Jörn Zaefferer, Paul McLanahan
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.metadata.js 3640 2007-10-11 18:34:38Z pmclanahan $
 *
 */

/**
 * Sets the type of metadata to use. Metadata is encoded in JSON, and each property
 * in the JSON will become a property of the element itself.
 *
 * There are four supported types of metadata storage:
 *
 *   attr:  Inside an attribute. The name parameter indicates *which* attribute.
 *          
 *   class: Inside the class attribute, wrapped in curly braces: { }
 *   
 *   elem:  Inside a child element (e.g. a script tag). The
 *          name parameter indicates *which* element.
 *   html5: Values are stored in data-* attributes.
 *          
 * The metadata for an element is loaded the first time the element is accessed via jQuery.
 *
 * As a result, you can define the metadata type, use $(expr) to load the metadata into the elements
 * matched by expr, then redefine the metadata type and run another $(expr) for other elements.
 * 
 * @name $.metadata.setType
 *
 * @example <p id="one" class="some_class {item_id: 1, item_label: 'Label'}">This is a p</p>
 * @before $.metadata.setType("class")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from the class attribute
 * 
 * @example <p id="one" class="some_class" data="{item_id: 1, item_label: 'Label'}">This is a p</p>
 * @before $.metadata.setType("attr", "data")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from a "data" attribute
 * 
 * @example <p id="one" class="some_class"><script>{item_id: 1, item_label: 'Label'}</script>This is a p</p>
 * @before $.metadata.setType("elem", "script")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from a nested script element
 * 
 * @example <p id="one" class="some_class" data-item_id="1" data-item_label="Label">This is a p</p>
 * @before $.metadata.setType("html5")
 * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
 * @desc Reads metadata from a series of data-* attributes
 *
 * @param String type The encoding type
 * @param String name The name of the attribute to be used to get metadata (optional)
 * @cat Plugins/Metadata
 * @descr Sets the type of encoding to be used when loading metadata for the first time
 * @type undefined
 * @see metadata()
 */

(function($) {

$.extend({
  metadata : {
    defaults : {
      type: 'class',
      name: 'metadata',
      cre: /({.*})/,
      single: 'metadata'
    },
    setType: function( type, name ){
      this.defaults.type = type;
      this.defaults.name = name;
    },
    get: function( elem, opts ){
      var settings = $.extend({},this.defaults,opts);
      // check for empty string in single property
      if ( !settings.single.length ) settings.single = 'metadata';
      
      var data = $.data(elem, settings.single);
      // returned cached data if it already exists
      if ( data ) return data;
      
      data = "{}";
      
      var getData = function(data) {
        if(typeof data != "string") return data;
        
        if( data.indexOf('{') < 0 ) {
          data = eval("(" + data + ")");
        }
      }
      
      var getObject = function(data) {
        if(typeof data != "string") return data;
        
        data = eval("(" + data + ")");
        return data;
      }
      
      if ( settings.type == "html5" ) {
        var object = {};
        $( elem.attributes ).each(function() {
          var name = this.nodeName;
          if(name.match(/^data-/)) name = name.replace(/^data-/, '');
          else return true;
          object[name] = getObject(this.nodeValue);
        });
      } else {
        if ( settings.type == "class" ) {
          var m = settings.cre.exec( elem.className );
          if ( m )
            data = m[1];
        } else if ( settings.type == "elem" ) {
          if( !elem.getElementsByTagName ) return;
          var e = elem.getElementsByTagName(settings.name);
          if ( e.length )
            data = $.trim(e[0].innerHTML);
        } else if ( elem.getAttribute != undefined ) {
          var attr = elem.getAttribute( settings.name );
          if ( attr )
            data = attr;
        }
        object = getObject(data.indexOf("{") < 0 ? "{" + data + "}" : data);
      }
      
      $.data( elem, settings.single, object );
      return object;
    }
  }
});

/**
 * Returns the metadata object for the first member of the jQuery object.
 *
 * @name metadata
 * @descr Returns element's metadata object
 * @param Object opts An object contianing settings to override the defaults
 * @type jQuery
 * @cat Plugins/Metadata
 */
$.fn.metadata = function( opts ){
  return $.metadata.get( this[0], opts );
};

})(jQuery);

/*
 ### jQuery Star Rating Plugin v3.13 - 2009-03-26 ###
 * Home: http://www.fyneworks.com/jquery/star-rating/
 * Code: http://code.google.com/p/jquery-star-rating-plugin/
 *
	* Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 ###
*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}(';5(29.1j)(7($){5($.1L.1J)1I{1t.1H("1K",J,H)}1M(e){};$.n.3=7(i){5(4.Q==0)k 4;5(A I[0]==\'1h\'){5(4.Q>1){8 j=I;k 4.W(7(){$.n.3.y($(4),j)})};$.n.3[I[0]].y(4,$.1T(I).1U(1)||[]);k 4};8 i=$.12({},$.n.3.1s,i||{});$.n.3.K++;4.2a(\'.9-3-1f\').o(\'9-3-1f\').W(7(){8 a,l=$(4);8 b=(4.23||\'21-3\').1v(/\\[|\\]/g,\'Z\').1v(/^\\Z+|\\Z+$/g,\'\');8 c=$(4.1X||1t.1W);8 d=c.6(\'3\');5(!d||d.18!=$.n.3.K)d={z:0,18:$.n.3.K};8 e=d[b];5(e)a=e.6(\'3\');5(e&&a)a.z++;x{a=$.12({},i||{},($.1b?l.1b():($.1S?l.6():s))||{},{z:0,F:[],v:[]});a.w=d.z++;e=$(\'<1R V="9-3-1Q"/>\');l.1P(e);e.o(\'3-15-T-17\');5(l.S(\'R\'))a.m=H;e.1c(a.E=$(\'<P V="3-E"><a 14="\'+a.E+\'">\'+a.1d+\'</a></P>\').1g(7(){$(4).3(\'O\');$(4).o(\'9-3-N\')}).1i(7(){$(4).3(\'u\');$(4).G(\'9-3-N\')}).1l(7(){$(4).3(\'r\')}).6(\'3\',a))};8 f=$(\'<P V="9-3 q-\'+a.w+\'"><a 14="\'+(4.14||4.1p)+\'">\'+4.1p+\'</a></P>\');e.1c(f);5(4.11)f.S(\'11\',4.11);5(4.1r)f.o(4.1r);5(a.1F)a.t=2;5(A a.t==\'1u\'&&a.t>0){8 g=($.n.10?f.10():0)||a.1w;8 h=(a.z%a.t),Y=1y.1z(g/a.t);f.10(Y).1A(\'a\').1B({\'1C-1D\':\'-\'+(h*Y)+\'1E\'})};5(a.m)f.o(\'9-3-1o\');x f.o(\'9-3-1G\').1g(7(){$(4).3(\'1n\');$(4).3(\'D\')}).1i(7(){$(4).3(\'u\');$(4).3(\'C\')}).1l(7(){$(4).3(\'r\')});5(4.L)a.p=f;l.1q();l.1N(7(){$(4).3(\'r\')});f.6(\'3.l\',l.6(\'3.9\',f));a.F[a.F.Q]=f[0];a.v[a.v.Q]=l[0];a.q=d[b]=e;a.1O=c;l.6(\'3\',a);e.6(\'3\',a);f.6(\'3\',a);c.6(\'3\',d)});$(\'.3-15-T-17\').3(\'u\').G(\'3-15-T-17\');k 4};$.12($.n.3,{K:0,D:7(){8 a=4.6(\'3\');5(!a)k 4;5(!a.D)k 4;8 b=$(4).6(\'3.l\')||$(4.U==\'13\'?4:s);5(a.D)a.D.y(b[0],[b.M(),$(\'a\',b.6(\'3.9\'))[0]])},C:7(){8 a=4.6(\'3\');5(!a)k 4;5(!a.C)k 4;8 b=$(4).6(\'3.l\')||$(4.U==\'13\'?4:s);5(a.C)a.C.y(b[0],[b.M(),$(\'a\',b.6(\'3.9\'))[0]])},1n:7(){8 a=4.6(\'3\');5(!a)k 4;5(a.m)k;4.3(\'O\');4.1a().19().X(\'.q-\'+a.w).o(\'9-3-N\')},O:7(){8 a=4.6(\'3\');5(!a)k 4;5(a.m)k;a.q.1V().X(\'.q-\'+a.w).G(\'9-3-1k\').G(\'9-3-N\')},u:7(){8 a=4.6(\'3\');5(!a)k 4;4.3(\'O\');5(a.p){a.p.6(\'3.l\').S(\'L\',\'L\');a.p.1a().19().X(\'.q-\'+a.w).o(\'9-3-1k\')}x $(a.v).1m(\'L\');a.E[a.m||a.1Y?\'1q\':\'1Z\']();4.20()[a.m?\'o\':\'G\'](\'9-3-1o\')},r:7(a,b){8 c=4.6(\'3\');5(!c)k 4;5(c.m)k;c.p=s;5(A a!=\'B\'){5(A a==\'1u\')k $(c.F[a]).3(\'r\',B,b);5(A a==\'1h\')$.W(c.F,7(){5($(4).6(\'3.l\').M()==a)$(4).3(\'r\',B,b)})}x c.p=4[0].U==\'13\'?4.6(\'3.9\'):(4.22(\'.q-\'+c.w)?4:s);4.6(\'3\',c);4.3(\'u\');8 d=$(c.p?c.p.6(\'3.l\'):s);5((b||b==B)&&c.1e)c.1e.y(d[0],[d.M(),$(\'a\',c.p)[0]])},m:7(a,b){8 c=4.6(\'3\');5(!c)k 4;c.m=a||a==B?H:J;5(b)$(c.v).S("R","R");x $(c.v).1m("R");4.6(\'3\',c);4.3(\'u\')},1x:7(){4.3(\'m\',H,H)},24:7(){4.3(\'m\',J,J)}});$.n.3.1s={E:\'25 26\',1d:\'\',t:0,1w:16};$(7(){$(\'l[27=28].9\').3()})})(1j);',62,135,'|||rating|this|if|data|function|var|star|||||||||||return|input|readOnly|fn|addClass|current|rater|select|null|split|draw|inputs|serial|else|apply|count|typeof|undefined|blur|focus|cancel|stars|removeClass|true|arguments|false|calls|checked|val|hover|drain|div|length|disabled|attr|be|tagName|class|each|filter|spw|_|width|id|extend|INPUT|title|to||drawn|call|andSelf|prevAll|metadata|append|cancelValue|callback|applied|mouseover|string|mouseout|jQuery|on|click|removeAttr|fill|readonly|value|hide|className|options|document|number|replace|starWidth|disable|Math|floor|find|css|margin|left|px|half|live|execCommand|try|msie|BackgroundImageCache|browser|catch|change|context|before|control|span|meta|makeArray|slice|children|body|form|required|show|siblings|unnamed|is|name|enable|Cancel|Rating|type|radio|window|not'.split('|'),0,{}))

$('.star').rating({
	callback: function(value, link){
	alert("This message is displayed by a callback function.\nThe function can be changed so it could put the rating valu in the database or read the value from it.\n\nThe value you chose is: "+ value);
}
});
$('.div.rating-cancel').hide();

//removing and restoring default input values

$(":text,textarea").each(function(){
	this.defaultText = this.value;
	$(this)
		.focus(function() { if (this.value == this.defaultText) this.value = ""; })
		.blur(function() { if (this.value == "" && this.defaultText) this.value = this.defaultText; });
});

// home page showcase

var speed = 500;
var duration = 3000;
var count = $(".slideshow li").length;
var maxIndex = count - 1;
var current = 0;
$(".slideshow li").not($(".slideshow li").eq(current)).hide();
$(".controls a").eq(current).addClass("current");
var play = true;

function changeSlide(){
	$(".slideshow li").eq(current).fadeOut(speed);
	if(current < maxIndex) current++;
	else current = 0;	
	$(".slideshow li").eq(current).fadeIn(speed);
	$(".controls a").removeClass("current");
	$(".controls a").eq(current).addClass("current");
	//test
	/*
$(".utils .current").html(current);
	$(".utils .index").html(index);
*/
}

var interval = setInterval(changeSlide, duration);

$(".controls a").not("a.pauseSlide").click(function(){
	clearInterval(interval);
	//$(".slideshow li").stop(true, true);
	$(".slideshow li").eq(current).fadeOut(speed);
	current = parseInt($(this).html(), 10) - 1;
	
	$(".slideshow li").eq(current).fadeIn(speed);
	$(".controls a").removeClass("current");
	$(".controls a").eq(current).addClass("current");
	//changeSlide();
	if(play) interval = setInterval(changeSlide, duration);
	return false; 
});


$(".controls a.pauseSlide").click(function(){
	$(".slideshow li").stop(true, true);
	$(this).toggleClass("play");
	if(play) clearInterval(interval);
	else interval = setInterval(changeSlide, duration);
	play = !play;
	return false; 
});

// faq answers toggling
$("p.q").click(function(){
	$(this).parent().parent().toggleClass("expanded");
});

/*
// setting focus on form elements in the same label
$("input, select").click(function(){ $(this).focus(); });
$("input, select").parent().click(function(){
	if($(this).children("input").length > 1 || $(this).children("select").length > 1) return false;
});
*/

// tabs
$(".tab-controls a").eq(0).addClass("active");
$(".tab-controls form").not($(".tab-controls form").eq(0)).hide();
$(".tabbed").not($(".tabbed").eq(0)).hide();
$(".tab-controls a").click(function(){
	$(".tab-controls a").removeClass("active");
	$(this).addClass("active");
	$(".tab-controls form").hide();
	$(".tabbed").hide();
	var index = $(this).parent().prevAll("li").length;
	$(".tab-controls form").eq(index).show();
	$(".tabbed").eq(index).show();
	return false;
});


// get page size
function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

//preloading photos
var images = new Array();
for(i = 0; i < $("a.photo").length; i++){
	
	images[i] = new Image();
	
	images[i].src = $("a.photo").eq(i).attr("href");

}

// show photo
function showPhoto(index){
	$(".popup.photo").prepend('<img src="' + index + '" alt="" />');
	var pagesize = getPageSize();
	var x = pagesize[0]-250;
	var y = pagesize[1]-250;
	
	var imageWidth = $(".popup.photo img").width();
	var imageHeight = $(".popup.photo img").height();
	
	if (imageWidth > x) 
	{
		imageHeight = imageHeight * (x / imageWidth); 
		imageWidth = x; 
		if (imageHeight > y) 
		{ 
			imageWidth = imageWidth * (y / imageHeight); 
			imageHeight = y; 
		}
	} 
	else if (imageHeight > y) 
	{ 
		imageWidth = imageWidth * (y / imageHeight); 
		imageHeight = y; 
		if (imageWidth > x) 
		{ 
			imageHeight = imageHeight * (x / imageWidth); 
			imageWidth = x;
		}
	}

	// need to display the pop up correctly.
	//$(".show-photo a").height(parseInt(imageHeight, 10));
	if (imageWidth < 400)
	{
	$(".popup.photo").css("width", + 400 + "px");
	}
	else
	{
	$(".popup.photo").css("width", imageWidth + 30 + "px");
	}

	$(".popup.photo img").css("width", imageWidth + "px");
	$(".popup.photo img").css("height", imageHeight + "px");
	
		
		
	$(".popup.photo").css("top", "100px");
	if($.browser.msie){
	$(".popup.photo").css("left", pagesize[1]/2+100);
	}
	else
	{
	$(".popup.photo").css("left", pagesize[1]/2+250);
	}
}


$("a.show-photo").click(function(){
	currentIndex = $(this).attr("href");
	showPhoto(currentIndex);
	
	$(".overlay, .popup.photo").show();
	return false;
});


/* showing and hiding modal windows */
$("a.show-video, a.show-audio, a.show-popup, a.show").click(function(){
	$(".overlay").show();
	//$(".modal.video").show(); 
	var media = $(this).attr("href");
	if(media.indexOf('video') != -1)
	{
		//var frameHeight = 500;
		var frameWidth = 513;
	}
	else
	{
		//var frameHeight = 180;
		var frameWidth = 580;
	}
	$('body').append("<div class='modal' style='width:" + frameWidth + "px;'><iframe frameborder=\"0\" allowTransparency=\"true\" id=\"avpop\" SCROLLING=NO  style=\"background:transparent; width:"+frameWidth +"px;overflow:hidden;height:100%;\" src=\"" + media + "\"></iframe></div>");
	return false;
});

/*$("a.show-audio").click(function(){
	$(".overlay").show();
	$(".modal.audio").show();
	return false;
});
*/
$("a.show-email").click(function(){
	$(".overlay").show();
	$(".modal.email").show();
	return false;
});

$("a.close, .overlay").click(function(){
	
	parent.PopupClose();
	
});
		 
function PopupClose()
{
	
	if($('.modal').css('display') != 'block'){	
		$(".modal").remove();
		$(".overlay").hide();
	}else{
		$(".overlay, .modal").css('display',"none");
	
	}
	return false;
}


$(".overlay").click(function(){
	$(".modal").hide();
	$(".popup.photo").hide();
	$(".popup.photo").attr("style"," ");
	$(".popup.photo img").remove();
	$(".overlay").hide();
}); 

$('select#location_province').change(function(){
		var selOpt = $(this).val().toLowerCase();
		var cty = $("select#location_city");
		var pageid = $("input#pageid").val();
		if(selOpt != 0){
		
			$.post("/ajax/type/getlocation", "location_province="+selOpt+"&pageid="+pageid,function(data){
																
				if(data.length > 0){
					cty.html(data);
					cty.removeAttr("disabled");
					cty.prev().removeClass("select-disabled");
					cty.prev().children().text(cty.children("option:selected").text());
				}else{
					var cloned = $(cty.children().get(0)).clone();
					cty.html("");
					cty.append(cloned);
					cty.attr("disabled","disabled");
					cty.prev().addClass("select-disabled");
					cty.prev().children().text(cty.children("option:selected").text());

				}
			});
		}else{
			var cloned = $(cty.children().get(0)).clone();
			cty.html("");
			cty.append(cloned);
			cty.attr("disabled","disabled");
			cty.prev().addClass("select-disabled");
			cty.prev().children().text(cty.children("option:selected").text());
		}
})

/**
 * workarounds for ie
 */
if($.browser.msie){
	$(".footer .col4 li:last-child").addClass("last");
	
}

/*
* table style for events
*/
$("tr").each(function(index)
{
	if (index%2==0)
	$(this).addClass("zebra");
});

$('.checkout-outcome').append('<br><a href="##" class="button3 print"><span>Print Receipt</span></a>')

$('.print').live("click",function(){

	window.print();
	return false;
})

