/*
 *     SCRIPT:	Function Definitions
 *    UPDATED:	12.27.2009


   RUNTIME GLOBALS (DO NOT MODIFY)
 * -------------------------------- */
var working = false;
var featured_loop = null;
var menu_timeoutID = null;
pngfix_elements = "div, a, li, img, input";


/* ENABLE JS FEATURES
 * Enables the user interface elements
 * that provide javascript functionality
 * -------------------------------------- */
function enable_js_features() {
	var selector = "";
	selector += "#content #featured #featured-body #featured-nav-ui" + ", ";
	selector += "#content #featured #featured-body a.nav-left," + ", ";
	selector += "#content #featured #featured-body a.nav-right," + ", ";
	//selector += "" + ", ";
	
	// Trim the last comma and space
	var strLen = selector.length;
	selector = selector.slice(0,strLen-2);

	// Show the elements
	jQuery(selector).css('display', 'block');
}

/* CLICK EVENTS
 * Here JS click() events are defined
 * ------------------------------------ */
function click_events() {
	
	$('#back-to-top').click(function(){
		if ( is_IE6() || is_IE7() ) {
			$('html').animate({scrollTop:0}, 700);
			return false;
		}
		
		if ( !$.browser.opera ) {
			$('html,body').animate({scrollTop:0}, {
				duration: 800,
				easing: 'easeInOutExpo'
			});
		} else {
			$('html').animate({scrollTop:0}, {
				duration: 800,
				easing: 'easeInOutExpo'
			});
		}
		return false;
	});

	$('#featured-body a.nav-left, #featured-body a.nav-right').click(next_featured);

	$('a.close-btn').click(function() {
		
		if ( ! is_IE6() ) {
			$(this).parent().fadeOut(forms_notification_delay);
			return false;
		} 
		
	});
}

/* HOVER EVENTS
 * Here JS hover() events are defined
 * ------------------------------------ */
function hover_events() {

	if ( stop_featured_cycle_on_hover == true ) {
		$('#featured-content p, #featured-content h1, #featured-content a.button, #featured-body .frame img').hover(function() {
			clearTimeout(featured_loop);
		}, function() {
			if (enable_featured_cycle == true) { featured_cycle(); }
		});
	}
	
	$('#searchform').hover(function() {
		
		$('#search-focus-block').css('display', 'none');
		
	});
	
}

/* FORMS INITIALIZATION
 * Initializes forms, AJAX & Validation
 * --------------------------------------- */
function init_forms() {
	submitted_form = false;

	// Form Validation
	$('form.validate input[type=submit]').click(function() {
		var validated = false;
		var wp_comments = false;
		var parent = $(this).parents('form');
		if ( parent.attr('id') == 'commentform' ) { wp_comments = true; }
		parent.validate(function() {
			if (submitted_form) {alert('Your message/comment is on the way, thanks.');return false;}
			validated = true; 
			if ( wp_comments ) { return false; }
			jQuery.ajax({
				type: "POST",
				url: parent.attr('action'),
				data: form_data,
				success: function(response){
					if (response=='success') {
						parent.find('.post-msg').slideDown(400);
						submitted_form = true;
					}
				}
			});
		});
		if (validated && wp_comments) { return true; }
		else { return false; }

	});
}

/* VALIDATION FRAMEWORK (EXTENSION)
 * AJAX & Validation
 * --------------------------------------- */
$.fn.validate = function(callback) {
	var regexp_types = [ 'name', 'author', 'email', 'message', 'comment', 'url' ]
	var regexps = {
		'name' : /[a-zA-Z ]{2,30}/i,
		'author' : /[a-zA-Z ]{2,30}/i,
		'email' : /[\w-+]+(?:\.[\w-+]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}/i,
		'url': /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
	}

	var valid = true;
	form_data = "ajax=true&";
	for ( var i=0; i < regexp_types.length; i++ ) {
		var name = regexp_types[i];
		var rx = regexps[name];

		var input = jQuery('input[name=' + name + ']');
		var textarea = jQuery('textarea[name=' + name + ']');

		if ( input.length == 1 ) {
			if ( input.val().match(rx) == input.val() ) {
				input.removeClass('invalid');
				form_data += input.attr('name') + '=' + input.val() + '&';
			} else {
				// if not required and empty, let go
				if ( ! input.hasClass('required') && $.trim(input.val()) == '' ) {}
				else { valid = false; input.addClass('invalid'); }
			}
		}

		if ( textarea.length == 1 ) {
			if ( textarea.val().match(rx) == textarea.val() || $.trim(textarea.val()) != '' ) {
				textarea.removeClass('invalid');
				form_data += textarea.attr('name') + '=' + textarea.val().replace('&','&amp;') + '&';
			} else {
				// if not required and empty, let go
				if ( ! textarea.hasClass('required') && $.trim(textarea.val()) == '' ) {}
				else { valid = false; textarea.addClass('invalid'); }
			}
		}
	}

	if (valid) {
		form_data = form_data.substring(0, form_data.length-1);
		callback();
	}
}

/* LIGHTBOX INITIALIZATION
 * Prettyphoto Lightbox configuration. 
 * --------------------------------------- */
function init_lightbox() {
	
	if ( enable_lightbox == true ) {

		$("a[rel^='lightbox']").prettyPhoto({
			animationSpeed: lightbox_animation_speed, /* fast/slow/normal */
			padding: lightbox_padding, /* padding for each side of the picture */
			opacity: lightbox_opacity, /* Value betwee 0 and 1 */
			showTitle: lightbox_showtitle, /* true/false */
			allowresize: lightbox_allowresize, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: lightbox_theme, /* light_rounded / dark_rounded / light_square / dark_square */
			hideflash: lightbox_hideflash, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			modal: lightbox_modal_state, /* If set to true, only the close button will close the window */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){} /* Called when prettyPhoto is closed */
		});

	}
	
}

/* MENU INITIALIZATION
 * 
 * Initializes the menu and makes sure
 * it is cross platform and cross browser.
 * 
 * On IE6, the dropdown menu will only
 * work with JS enabled, since IE lacks
 * support for CSS's > selector, which is
 * used to unhide the unordered list.
 * --------------------------------------- */
function init_menu() {
	
	if ( is_IE6() ) {
		
		// Apply Blue Theme Fixes
		var bg = $('#content').css('background-image');
		if ( bg.indexOf('/blue/') != -1 ) {
				$('#header .container ul#navigation li ul').css({
					'background-image' : 'none',
					'background-color' : '#E1E1E1'
				});	
				
				$('#header .container ul#navigation li ul li a').css({'border-color' : 'E1E1E1'	}).hover(function() {
					$(this).css('border-color', '#cacaca');
				}, function() {
					$(this).css('border-color', '#E1E1E1');
				});
		}
		
		$('#header .container ul#navigation li').hover(function() {

			if ( $(this).children().length > 1 ) { 

				var _this = $(this);
				
				clearTimeout(menu_timeoutID);
				menu_timeoutID = setTimeout(function() {

					_this.find('ul:first').css({ visibility: "visible", display: "none" }).slideDown(menu_dropdown_duration, menu_ease_equation);

				},menu_show_delay);

			}			
			
		}, function() {

			clearTimeout(menu_timeoutID);
			$(this).find('ul:first').css({visibility: "hidden"});
			
		});
		
	} else {
		
		if ( is_IE7() ) {
			$('#header .container ul#navigation li ul').css('margin-left', '0');
		}
		
		$('#header .container ul#navigation li').hover(function() {
			
			$(this).find('ul:first').css({'visibility': 'hidden', 'display': 'none'});
			
			var _this = $(this);
		
			clearTimeout(menu_timeoutID);
			menu_timeoutID = setTimeout(function() {
				$('#search-focus-block').css('display', 'block');
				_this.find('ul:first').css({ visibility: "visible", display: "none" }).slideDown(menu_dropdown_duration, menu_ease_equation);
			},menu_show_delay);
				
		}, function() {
			
			clearTimeout(menu_timeoutID);
			$(this).find('ul:first').css({visibility: "hidden"});
				
		});
	}
}

/* FEATURED HOME INITIALIZATION
 * Configures, Retrieves and Creates elements
 * needed for this section to work. The cache
 * class is used here. 
 * --------------------------------------- */
function init_featured_home() {

	var featured_cache = $('#featured-items');
	var featured_nav = $('#featured-nav-ui');
	var items = featured_cache.children().length;

	for ( var i=1; i < items; i++ ) {
		featured_nav.append('<li><a rel="' + (i+1) + '" href="#"></a></li>');
	}

	featured_nav_click();
	
	if (enable_featured_cycle == true) { featured_cycle(); }
	
}

/* FEATURED CYCLE
 * Cycles the featured items an interval
 * defined by featured_cycle_interval. 
 * --------------------------------------- */
function featured_cycle() {

	if ( featured_cycle_interval < 60 ) { featured_cycle_interval *= 1000 }

	featured_loop = setInterval(function() {
		
		next_featured();
		
	},featured_cycle_interval);

}

/* NEXT FEATURED
 * Smart & Multipurpose function that 
 * changes the featured items. Also serves
 * as the click() event handler for the
 * featured content switchers. 
 * --------------------------------------- */
function next_featured() {
	var increment = 1;
	if ( $(this).hasClass('nav-left') ) { increment = -1; clearInterval(featured_loop); featured_loop = null; }
	if ( $(this).hasClass('nav-right') ) { increment = 1; clearInterval(featured_loop); featured_loop = null; }
	
	var items = $('#featured-items').children().length;
	var current = $('#featured-nav-ui li.active a').attr('rel');
	var next = cycle(parseInt(items), parseInt(current), increment );

	var selector = '#featured-nav-ui li a[rel=' + next + ']';
	$(selector).parent().click();

	return false;

}

/* PRECACHE
 * Preloads the slideshow images
 * --------------------------------------- */
function precache() {
	var images = $('ul#featured-items li img');
	images.each(function(i) {
		var src = $(this).attr('src');
		$.cacheImage(src, {
			load: function() { 
				cached_images[src] = $(this); 
				if (i+1 == images.length) { init_featured_home() }
			}
		});
	});
}

/* FEATURED NAV ELEMENTS CLICK
 * Handles the switching when the featured
 * items navigation (bottom right) elements
 * are clicked.
 * --------------------------------------- */
function featured_nav_click() {
	$('#featured-nav-ui li').click(function() {
		if ( $(this).hasClass('active') || working == true ) { return false; }
		
		working = true;

		var featured_cache = $('#featured-items');
		
		var num = $(this).children().eq(0).attr('rel') - 1;
		var block = featured_cache.children().eq(num);
		var h1 = block.children().eq(0).text();
		var img = block.children().eq(1).attr('src');
		var p = block.children().eq(2).text();
		var href = block.children().eq(3).attr('href');
		
		var duration = 900;
		
		var text_fade_duration = duration*0.4

		$('#featured-nav-ui li').removeClass('active');
		$(this).addClass('active');

		// Get the next image from cache
		var new_backImage = cached_images[img]; new_backImage.addClass('back');

		// Remove old image
		$('#featured-body img.back').remove();
		new_backImage.appendTo('#featured-body').attr('style','position:absolute; top: 30px; left: 56px;');

		// Get Elements
		backImage = $('#featured-body img.back');
		frontImage= $('#featured-body img.front');
		
		// Fade Out front image
		frontImage.animate({'opacity':'0'},duration);

		setTimeout(function() {
			// Swap Classes, bring FrontImage to back, and set opacity back to 1 again.
			backImage.removeClass('back'); frontImage.removeClass('front');
			backImage.addClass('front'); frontImage.addClass('back').css('opacity','1');

			working = false;
			if ( featured_loop == null ) { 
				if (enable_featured_cycle == true) { featured_cycle(); }
			}
		},duration+30);

		if ( !$.browser.msie || disable_text_fade_on_ie == false ) {
			$('#featured-content h1, #featured-content p').stop().animate({
				'opacity' : '0'
			},text_fade_duration);
		}

		setTimeout(function() {
			$('#featured-content h1').text(h1);
			$('#featured-content p').text(p);
			$('#featured-content a.button').attr('href', href);
			
			if ( !$.browser.msie || disable_text_fade_on_ie == false ) {
				$('#featured-content h1, #featured-content p').animate({
					'opacity' : '1'
				},text_fade_duration);
			}
	
		},text_fade_duration+30);

		return false;
	});
}

/* CYCLE
 * Cycling Algorithm
 * --------------------------------------- */
function cycle(range, current, increment) {
	var item = current + increment;
	if ( item == 0 ) { item = range; }
	if ( item > range ) { item = 1;	}
	return item;
}

/* TARGET _BLANK SUPPORT IN JS
 * The XHTML 1.0 Strict doctype, doesn't
 * support the target="_blank" attribute,
 * so it's added on JS in order to validate.
 * --------------------------------------- */
function setup_external_links() {
	$('a[rel=_blank]').attr('target', '_blank');
}

/* IE6 DETECTION
 * Detects Internet Explorer 6
 * --------------------------------------- */
function is_IE6() {
	return (navigator.appVersion.indexOf("MSIE 6.")==-1) ? false : true;
}

/* IE7 DETECTION
 * Detects Internet Explorer 7
 * --------------------------------------- */
function is_IE7() {
	return (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
}

/* IE6/7 DETECTION
 * Detects Internet Explorer 6 and/or 7
 * --------------------------------------- */
function is_IE67() {
	if ( is_IE6() || is_IE7() ) {
		return true;
	} else {
		return false;
	}
}

/* JS STYLE ENHANCEMENTS
 * Enables user interface enhancements 
 * using javascript
 * -------------------------------------- */
function js_enhancements() {
	$('body ul#recentcomments li.recentcomments').each(function() {
		var code = $(this).html(); code = code.replace(' on <a href=', ' on <br/> <a href='); 	$(this).html(code);		
	});
}

/* JQUERY EXTENSIONS */
/*
 * cacheImage: a jQuery plugin
 *
 * cacheImage is a simple jQuery plugin for pre-caching images.  The
 * plugin can be used to eliminate flashes of unstyled content (FOUC) and
 * improve perceived page load time.  Callbacks for load, error and abort
 * events are provided.
 *
 * For usage and examples, visit:
 * http://github.com/alexrabarts/jquery-cacheimage
 *
 * Licensed under the MIT:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright (c) 2008 Stateless Systems (http://statelesssystems.com)
 *
 * @author   Alex Rabarts (alexrabarts -at- gmail -dawt- com)
 * @requires jQuery v1.2 or later
 * @version  0.2.1
 */

(function ($) {
  $.extend($, {
    cacheImage: function (src, options) {
      if (typeof src === 'object') {
        $.each(src, function () {
          $.cacheImage(String(this), options);
        });

        return;
      }

      var image = new Image();

      options = options || {};

      $.each(['load', 'error', 'abort'], function () { // Callbacks
        var e = String(this);
        if (typeof options[e] === 'function') { $(image).bind(e, options[e]); }

        if (typeof options.complete === 'function') {
          $(image).bind(e, options.complete);
        }
      });

      image.src = src;

      return image;
    }
  });

  $.extend($.fn, {
    cacheImage: function (options) {
      return this.each(function () {
        $.cacheImage(this.src, options);
      });
    }
  });
})(jQuery);

/* PRETTYPHOTO */
(function($){$.prettyPhoto={version:'2.5.4'};$.fn.prettyPhoto=function(settings){settings=jQuery.extend({animationSpeed:'normal',padding:40,opacity:0.80,showTitle:true,allowresize:true,counter_separator_label:'/',theme:'light_rounded',hideflash:false,modal:false,changepicturecallback:function(){},callback:function(){}},settings);if($.browser.msie&&$.browser.version==6){settings.theme="light_square";}
if($('.pp_overlay').size()==0){_buildOverlay();}else{$pp_pic_holder=$('.pp_pic_holder');$ppt=$('.ppt');}
var doresize=true,percentBased=false,correctSizes,$pp_pic_holder,$ppt,pp_contentHeight,pp_contentWidth,pp_containerHeight,pp_containerWidth,pp_type='image',setPosition=0,$scrollPos=_getScroll();$(window).scroll(function(){$scrollPos=_getScroll();_centerOverlay();_resizeOverlay();});$(window).resize(function(){_centerOverlay();_resizeOverlay();});$(document).keydown(function(e){if($pp_pic_holder.is(':visible'))
switch(e.keyCode){case 37:$.prettyPhoto.changePage('previous');break;case 39:$.prettyPhoto.changePage('next');break;case 27:if(!settings.modal)
$.prettyPhoto.close();break;};});$(this).each(function(){$(this).bind('click',function(){link=this;theRel=$(this).attr('rel');galleryRegExp=/\[(?:.*)\]/;theGallery=galleryRegExp.exec(theRel);var images=new Array(),titles=new Array(),descriptions=new Array();if(theGallery){$('a[rel*='+theGallery+']').each(function(i){if($(this)[0]===$(link)[0])setPosition=i;images.push($(this).attr('href'));titles.push($(this).find('img').attr('alt'));descriptions.push($(this).attr('title'));});}else{images=$(this).attr('href');titles=($(this).find('img').attr('alt'))?$(this).find('img').attr('alt'):'';descriptions=($(this).attr('title'))?$(this).attr('title'):'';}
$.prettyPhoto.open(images,titles,descriptions);return false;});});$.prettyPhoto.open=function(gallery_images,gallery_titles,gallery_descriptions){if($.browser.msie&&$.browser.version==6){$('select').css('visibility','hidden');};if(settings.hideflash)$('object,embed').css('visibility','hidden');images=$.makeArray(gallery_images);titles=$.makeArray(gallery_titles);descriptions=$.makeArray(gallery_descriptions);if($('.pp_overlay').size()==0){_buildOverlay();}else{$pp_pic_holder=$('.pp_pic_holder');$ppt=$('.ppt');}
$pp_pic_holder.attr('class','pp_pic_holder '+settings.theme);isSet=($(images).size()>0)?true:false;_getFileType(images[setPosition]);_centerOverlay();_checkPosition($(images).size());$('.pp_loaderIcon').show();$('div.pp_overlay').show().fadeTo(settings.animationSpeed,settings.opacity,function(){$pp_pic_holder.fadeIn(settings.animationSpeed,function(){$pp_pic_holder.find('p.currentTextHolder').text((setPosition+1)+settings.counter_separator_label+$(images).size());if(descriptions[setPosition]){$pp_pic_holder.find('.pp_description').show().html(unescape(descriptions[setPosition]));}else{$pp_pic_holder.find('.pp_description').hide().text('');};if(titles[setPosition]&&settings.showTitle){hasTitle=true;$ppt.html(unescape(titles[setPosition]));}else{hasTitle=false;};if(pp_type=='image'){imgPreloader=new Image();nextImage=new Image();if(isSet&&setPosition>$(images).size())nextImage.src=images[setPosition+1];prevImage=new Image();if(isSet&&images[setPosition-1])prevImage.src=images[setPosition-1];pp_typeMarkup='<img id="fullResImage" src="" />';$pp_pic_holder.find('#pp_full_res')[0].innerHTML=pp_typeMarkup;$pp_pic_holder.find('.pp_content').css('overflow','hidden');$pp_pic_holder.find('#fullResImage').attr('src',images[setPosition]);imgPreloader.onload=function(){correctSizes=_fitToViewport(imgPreloader.width,imgPreloader.height);_showContent();};imgPreloader.src=images[setPosition];}else{movie_width=(parseFloat(grab_param('width',images[setPosition])))?grab_param('width',images[setPosition]):"425";movie_height=(parseFloat(grab_param('height',images[setPosition])))?grab_param('height',images[setPosition]):"344";if(movie_width.indexOf('%')!=-1||movie_height.indexOf('%')!=-1){movie_height=($(window).height()*parseFloat(movie_height)/100)-100;movie_width=($(window).width()*parseFloat(movie_width)/100)-100;percentBased=true;}
movie_height=parseFloat(movie_height);movie_width=parseFloat(movie_width);if(pp_type=='quicktime')movie_height+=15;correctSizes=_fitToViewport(movie_width,movie_height);if(pp_type=='youtube'){pp_typeMarkup='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.youtube.com/v/'+grab_param('v',images[setPosition])+'" /><embed src="http://www.youtube.com/v/'+grab_param('v',images[setPosition])+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"></embed></object>';}else if(pp_type=='quicktime'){pp_typeMarkup='<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+correctSizes['height']+'" width="'+correctSizes['width']+'"><param name="src" value="'+images[setPosition]+'"><param name="autoplay" value="true"><param name="type" value="video/quicktime"><embed src="'+images[setPosition]+'" height="'+correctSizes['height']+'" width="'+correctSizes['width']+'" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';}else if(pp_type=='flash'){flash_vars=images[setPosition];flash_vars=flash_vars.substring(images[setPosition].indexOf('flashvars')+10,images[setPosition].length);filename=images[setPosition];filename=filename.substring(0,filename.indexOf('?'));pp_typeMarkup='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="'+filename+'?'+flash_vars+'" /><embed src="'+filename+'?'+flash_vars+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"></embed></object>';}else if(pp_type=='iframe'){movie_url=images[setPosition];movie_url=movie_url.substr(0,movie_url.indexOf('iframe')-1);pp_typeMarkup='<iframe src ="'+movie_url+'" width="'+(correctSizes['width']-10)+'" height="'+(correctSizes['height']-10)+'" frameborder="no"></iframe>';}
_showContent();}});});};$.prettyPhoto.changePage=function(direction){if(direction=='previous'){setPosition--;if(setPosition<0){setPosition=0;return;}}else{if($('.pp_arrow_next').is('.disabled'))return;setPosition++;};if(!doresize)doresize=true;_hideContent();$('a.pp_expand,a.pp_contract').fadeOut(settings.animationSpeed,function(){$(this).removeClass('pp_contract').addClass('pp_expand');$.prettyPhoto.open(images,titles,descriptions);});};$.prettyPhoto.close=function(){$pp_pic_holder.find('object,embed').css('visibility','hidden');$('div.pp_pic_holder,div.ppt').fadeOut(settings.animationSpeed);$('div.pp_overlay').fadeOut(settings.animationSpeed,function(){$('div.pp_overlay,div.pp_pic_holder,div.ppt').remove();if($.browser.msie&&$.browser.version==6){$('select').css('visibility','visible');};if(settings.hideflash)$('object,embed').css('visibility','visible');setPosition=0;settings.callback();});doresize=true;};_showContent=function(){$('.pp_loaderIcon').hide();if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth;}else{windowHeight=$(window).height();windowWidth=$(window).width();};projectedTop=$scrollPos['scrollTop']+((windowHeight/2)-(correctSizes['containerHeight']/2));if(projectedTop<0)projectedTop=0+$pp_pic_holder.find('.ppt').height();$pp_pic_holder.find('.pp_content').animate({'height':correctSizes['contentHeight']},settings.animationSpeed);$pp_pic_holder.animate({'top':projectedTop,'left':((windowWidth/2)-(correctSizes['containerWidth']/2)),'width':correctSizes['containerWidth']},settings.animationSpeed,function(){$pp_pic_holder.width(correctSizes['containerWidth']);$pp_pic_holder.find('.pp_hoverContainer,#fullResImage').height(correctSizes['height']).width(correctSizes['width']);$pp_pic_holder.find('#pp_full_res').fadeIn(settings.animationSpeed);if(isSet&&pp_type=="image"){$pp_pic_holder.find('.pp_hoverContainer').fadeIn(settings.animationSpeed);}else{$pp_pic_holder.find('.pp_hoverContainer').hide();}
$pp_pic_holder.find('.pp_details').fadeIn(settings.animationSpeed);if(settings.showTitle&&hasTitle){$ppt.css({'top':$pp_pic_holder.offset().top-20,'left':$pp_pic_holder.offset().left+(settings.padding/2),'display':'none'});$ppt.fadeIn(settings.animationSpeed);};if(correctSizes['resized'])$('a.pp_expand,a.pp_contract').fadeIn(settings.animationSpeed);if(pp_type!='image')$pp_pic_holder.find('#pp_full_res')[0].innerHTML=pp_typeMarkup;settings.changepicturecallback();});};function _hideContent(){$pp_pic_holder.find('#pp_full_res object,#pp_full_res embed').css('visibility','hidden');$pp_pic_holder.find('.pp_hoverContainer,.pp_details').fadeOut(settings.animationSpeed);$pp_pic_holder.find('#pp_full_res').fadeOut(settings.animationSpeed,function(){$('.pp_loaderIcon').show();});$ppt.fadeOut(settings.animationSpeed);}
function _checkPosition(setCount){if(setPosition==setCount-1){$pp_pic_holder.find('a.pp_next').css('visibility','hidden');$pp_pic_holder.find('a.pp_arrow_next').addClass('disabled').unbind('click');}else{$pp_pic_holder.find('a.pp_next').css('visibility','visible');$pp_pic_holder.find('a.pp_arrow_next.disabled').removeClass('disabled').bind('click',function(){$.prettyPhoto.changePage('next');return false;});};if(setPosition==0){$pp_pic_holder.find('a.pp_previous').css('visibility','hidden');$pp_pic_holder.find('a.pp_arrow_previous').addClass('disabled').unbind('click');}else{$pp_pic_holder.find('a.pp_previous').css('visibility','visible');$pp_pic_holder.find('a.pp_arrow_previous.disabled').removeClass('disabled').bind('click',function(){$.prettyPhoto.changePage('previous');return false;});};if(setCount>1){$('.pp_nav').show();}else{$('.pp_nav').hide();}};function _fitToViewport(width,height){hasBeenResized=false;_getDimensions(width,height);imageWidth=width;imageHeight=height;windowHeight=$(window).height();windowWidth=$(window).width();if(((pp_containerWidth>windowWidth)||(pp_containerHeight>windowHeight))&&doresize&&settings.allowresize&&!percentBased){hasBeenResized=true;notFitting=true;while(notFitting){if((pp_containerWidth>windowWidth)){imageWidth=(windowWidth-200);imageHeight=(height/width)*imageWidth;}else if((pp_containerHeight>windowHeight)){imageHeight=(windowHeight-200);imageWidth=(width/height)*imageHeight;}else{notFitting=false;};pp_containerHeight=imageHeight;pp_containerWidth=imageWidth;};_getDimensions(imageWidth,imageHeight);};return{width:imageWidth,height:imageHeight,containerHeight:pp_containerHeight,containerWidth:pp_containerWidth,contentHeight:pp_contentHeight,contentWidth:pp_contentWidth,resized:hasBeenResized};};function _getDimensions(width,height){$pp_pic_holder.find('.pp_details').width(width).find('.pp_description').width(width-parseFloat($pp_pic_holder.find('a.pp_close').css('width')));pp_contentHeight=height+$pp_pic_holder.find('.pp_details').height()+parseFloat($pp_pic_holder.find('.pp_details').css('marginTop'))+parseFloat($pp_pic_holder.find('.pp_details').css('marginBottom'));pp_contentWidth=width;pp_containerHeight=pp_contentHeight+$pp_pic_holder.find('.ppt').height()+$pp_pic_holder.find('.pp_top').height()+$pp_pic_holder.find('.pp_bottom').height();pp_containerWidth=width+settings.padding;}
function _getFileType(itemSrc){if(itemSrc.match(/youtube\.com\/watch/i)){pp_type='youtube';}else if(itemSrc.indexOf('.mov')!=-1){pp_type='quicktime';}else if(itemSrc.indexOf('.swf')!=-1){pp_type='flash';}else if(itemSrc.indexOf('iframe')!=-1){pp_type='iframe'}else{pp_type='image';};};function _centerOverlay(){if($.browser.opera){windowHeight=window.innerHeight;windowWidth=window.innerWidth;}else{windowHeight=$(window).height();windowWidth=$(window).width();};if(doresize){$pHeight=$pp_pic_holder.height();$pWidth=$pp_pic_holder.width();$tHeight=$ppt.height();projectedTop=(windowHeight/2)+$scrollPos['scrollTop']-($pHeight/2);if(projectedTop<0)projectedTop=0+$tHeight;$pp_pic_holder.css({'top':projectedTop,'left':(windowWidth/2)+$scrollPos['scrollLeft']-($pWidth/2)});$ppt.css({'top':projectedTop-$tHeight,'left':(windowWidth/2)+$scrollPos['scrollLeft']-($pWidth/2)+(settings.padding/2)});};};function _getScroll(){if(self.pageYOffset){scrollTop=self.pageYOffset;scrollLeft=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){scrollTop=document.documentElement.scrollTop;scrollLeft=document.documentElement.scrollLeft;}else if(document.body){scrollTop=document.body.scrollTop;scrollLeft=document.body.scrollLeft;}
return{scrollTop:scrollTop,scrollLeft:scrollLeft};};function _resizeOverlay(){$('div.pp_overlay').css({'height':$(document).height(),'width':$(window).width()});};function _buildOverlay(){toInject="";toInject+="<div class='pp_overlay'></div>";toInject+='<div class="pp_pic_holder"><div class="pp_top"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div><div class="pp_content"><a href="#" class="pp_expand" title="Expand the image">Expand</a><div class="pp_loaderIcon"></div><div class="pp_hoverContainer"><a class="pp_next" href="#">next</a><a class="pp_previous" href="#">previous</a></div><div id="pp_full_res"></div><div class="pp_details clearfix"><a class="pp_close" href="#">Close</a><p class="pp_description"></p><div class="pp_nav"><a href="#" class="pp_arrow_previous">Previous</a><p class="currentTextHolder">0'+settings.counter_separator_label+'0</p><a href="#" class="pp_arrow_next">Next</a></div></div></div><div class="pp_bottom"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div></div>';toInject+='<div class="ppt"></div>';$('body').append(toInject);$('div.pp_overlay').css('opacity',0);$pp_pic_holder=$('.pp_pic_holder');$ppt=$('.ppt');$('div.pp_overlay').css('height',$(document).height()).hide().bind('click',function(){if(!settings.modal)
$.prettyPhoto.close();});$('a.pp_close').bind('click',function(){$.prettyPhoto.close();return false;});$('a.pp_expand').bind('click',function(){$this=$(this);if($this.hasClass('pp_expand')){$this.removeClass('pp_expand').addClass('pp_contract');doresize=false;}else{$this.removeClass('pp_contract').addClass('pp_expand');doresize=true;};_hideContent();$pp_pic_holder.find('.pp_hoverContainer, .pp_details').fadeOut(settings.animationSpeed);$pp_pic_holder.find('#pp_full_res').fadeOut(settings.animationSpeed,function(){$.prettyPhoto.open(images,titles,descriptions);});return false;});$pp_pic_holder.find('.pp_previous, .pp_arrow_previous').bind('click',function(){$.prettyPhoto.changePage('previous');return false;});$pp_pic_holder.find('.pp_next, .pp_arrow_next').bind('click',function(){$.prettyPhoto.changePage('next');return false;});$pp_pic_holder.find('.pp_hoverContainer').css({'margin-left':settings.padding/2});};};function grab_param(name,url){name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var regexS="[\\?&]"+name+"=([^&#]*)";var regex=new RegExp(regexS);var results=regex.exec(url);if(results==null)
return"";else
return results[1];}})(jQuery);


/* EASING EQUATIONS */
/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */



/*
 * jQuery dataForAjax plug-in 1.0
 *
 * http://www.biuuu.com/
 * http://plugins.jquery.com/project/dataForAjax
 *
 * Copyright (c) 2009 biuuu.com
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
jQuery.fn.dataForAjax = function(options){
	var message = [];
	var error = [];
	var searchKey = '';
	var key;
	var data = '';
	var status = false;
	var id = "#"+this.get()[0].id;
	setting = jQuery.extend({
		showMessage:'showmessage',
		message:message
	},options);
	
	
	jQuery("#"+setting.showMessage).empty();
	
	for(key in setting.message){
		searchKey +=key+',';
	}
	
	jQuery( id+ "  :text").each(function(){
		var name = jQuery(this).attr("name");
		var value = jQuery(this).attr("value");
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});
	
	jQuery( id+ "  :password").each(function(){
		var name = jQuery(this).attr("name");
		var value = jQuery(this).attr("value");
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});
	
	jQuery( id+ "  textarea").each(function(){
		var name = jQuery(this).attr("name");
		var value = jQuery(this).val();
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});	
	
	jQuery( id+ "  :radio:checked").each(function(){
		var name = jQuery(this).attr("name");
		var value = jQuery(this).attr("value");
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});
	
	jQuery( id+ "  :checkbox:checked").each(function(){
		var name = jQuery(this).attr("name");
		var value = jQuery(this).attr("value");
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});
	
	jQuery( id+ "  select option:selected").each(function(){
		var name = jQuery(this).parent("select").attr("name");
		var value = jQuery(this).attr("value");
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});	
	
	jQuery( id+ "  :hidden").each(function(){
		var name = jQuery(this).attr("name");
		var value = jQuery(this).attr("value");
		if(((searchKey.indexOf(name)) != -1) && (value == '')){
			error.push(setting.message[name]);
			jQuery(this).focus(); 
			status = true;
			return false;
		}
		data += '&'+name+'='+value; 
	});	
	if(status){
		jQuery("#"+setting.showMessage).html(error.join(","));
		return '';
	}
	return data;
}

/* EOF */
