//Firebugx
if (!window.console)
    window.console={};

if (!console.firebug) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
    "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];

    for (var i = 0; i < names.length; ++i) {
        if (!window.console[names[i]])
            window.console[names[i]] = function() {};
    }
}

(function(a){a.fn.textBoxInstructions=function(c,b){return this.each(function(){if(!b){b="instructions"}if(this.type=="password"){a(this).hide().after('<input type="text" class="surrogate '+a(this).attr("class")+'" />').blur(function(){if(this.value==""){a(this).hide();a(".surrogate",this.parentNode).show()}});a(".surrogate",this.parentNode).addClass(b).val(c).focus(function(){a(this).hide();a(":password",this.parentNode).show().focus()})}else{a(this).addClass(b).focus(function(){if(a(this).hasClass(b)){this.value="";a(this).removeClass(b)}}).blur(function(){if(this.value==""){this.value=c;a(this).addClass(b)}}).each(function(){this.value=c})}})}})(jQuery);jQuery.noConflict();
(function($){
	$(function(){
		$('#search .inputbox_search').textBoxInstructions("search...");
	
		$('.siteMessage')
			.hide()
			.each(function(){
				//Put in an each so that it only scrolls if .siteError is present.
				window.scrollTo(0,0);
			})
			.slideDown(700)
			;
		$('#siteNav>ul>li').hover(
			function(){ 
				$(this).addClass('sfHover');
				$(this)
					.find('ul')
					.stop()
					.css({'top':'100%','opacity':'','display':'none'})
					.fadeIn(200)
					.queue(function(){
						if ($.browser.msie && $.browser.version.substr(0,1) == '7')
						{
							this.style.removeAttribute('filter');
						}
						$(this).dequeue();
					})
					;
			},
			function(){ 
				$(this).removeClass('sfHover');
				$(this)
					.find('ul')
					.stop()
					.fadeOut(200)
					;
			}
		);
        $('.phocagalleryslideshow')
            .each(function(){
                var $this = $(this);
                var content = $this.find('.phocagallerycontent');
                var images = $this.data('pgslideshowimages');
                if (images && images.length > 1) {
                    var imageTags = jQuery.map(images, function(item, index){
                        return (index==0) ? null : '<span style="display:none;"><img src="'+item.src+'" alt="" /></span>';
                    });
                    content.append(imageTags.join(''));
                    $this
                        .find('.phocagalleryslideshowliner')
                        .prepend('<a href="#" class="prev"><img src="'+templateMediaUrl+'/images/prev_arrow.png" alt="Previous" /></a>')
                        .append('<a href="#" class="next"><img src="'+templateMediaUrl+'/images/next_arrow.png" alt="Next" /></a>')
                        .cycle({
                            "slideExpr":".phocagallerycontent span"
                            ,"prev":$this.find(".prev")
                            ,"next":$this.find(".next")
                            ,"pause":true
                        })
                        ;
                }
            })
            ;
        $('ul.multithumb')
            .each(function(){
                var cycleRoot = $(this);
                var slideExpr = 'a';

                cycleRoot.addClass('cycle');

                resizeContainer = function(container){
                    var slides = container.find(slideExpr);
                    var dimensions = slides.map(function(){
                        var $this = $(this);
                        var img = $this.find('img');
                        var width = img.attr('width');
                        var height = img.attr('height');
                        $this.width(width);
                        $this.height(height);
                        return {"width":width, "height":height};
                    });
                    var maxWidth = 0;
                    var maxHeight = 0;
                    $.each(dimensions, function(){
                        if (this.width > maxWidth) {
                            maxWidth = this.width;
                        }
                        if (this.height > maxHeight) {
                            maxHeight = this.height;
                        }
                    });
                    container.width(maxWidth);
                    container.height(maxHeight);
                }
                resizeContainer(cycleRoot);
                
                cycleRoot.cycle({
                    "slideExpr":slideExpr
                    ,"before": function(){
                        //center slides
                        var $this = $(this);
                        $this.css({"left": (cycleRoot.width() - $this.find('img').attr('width')) / 2, "top": (cycleRoot.height() - $this.find('img').attr('height')) / 2});
                    }
                    ,"pause":true
                })
                ;
            })
            ;
	});
})(jQuery);

