$(function() {
	initOverLabels();
	$("ul.piped-list>li:not(:last-child)").append("<span>|</span>");
});

// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions

function initOverLabels() {
	$("label.overlabel[@for]").each(function() {
		var label = $(this);
		label.attr("class", "overlabel-apply");
		var field = $("#" + label.attr("for"));
		if (field.val() != "")
			label.hide();
		field.focus(function() {
			label.hide();
		}).blur(function() {
			if (field.val() == "")
				label.show();
		});
		label.click(function() {
			field.trigger("focus");
		});
	});	
}

// used for links to objects like video. This will overlay the video on the screen. Requires jqModal.js.
$.fn.objectOverlay = function(w, h) {
	$(this).click(function() {
		var vid = $(this).attr("href");
		var objtag = "<div class=\"jqmWindow\">";
		objtag += "<a id=\"object-close\" class=\"jqmClose\" href=\"javascript:void(0);\">close X</a>";
		objtag += "<object id=\"vid\" width=\"" + w + "\" height=\"" + h + "\" data=\"" + vid + "\">";
		objtag += "<param name=\"src\" value=\"" + vid + "\"/>";
		objtag += "<p>Video for " + vid + "</p>";
		objtag += "</object></div>";
		$(objtag).appendTo("body").jqm({onHide: function(hash) {
			hash.w.remove();
			hash.o.remove();
			if ($.browser.msie)
				document.location = document.location;
		}}).jqmShow();
		return false;
	});
};

function pluralize(word, count) 
{
	var plural = "";
	if (count != 1) 
	{
		switch (word)
		{
			case "match":
				plural = "es";
				break;
			default:
				plural = "s";
				break;
		}
	}
	return count + " " + word + plural;
}

$.extend({
    inArray: function( elem, array, start ) {
        if (start == null)
            start = 0;
            
		for ( var i = start, length = array.length; i < length; i++ )
			if ( array[ i ] == elem )
				return i;

		return -1;
	},
	
	inArrayAll: function( elem, array ) {
	    var indices = [];
        var idx = $.inArray(elem, array, 0);
        while (idx != -1)
        {
            indices.push(idx);
            idx = $.inArray(elem, array, idx + 1);
        }
        
        return indices;
	}
});


/***********************************************************************************************
	
Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com
	
UPDATE LOG:
	
March, 10th, 2006 : Added support for a message while large image is loading
	
Get this and other scripts at www.dhtmlgoodies.com
	
You can use this script freely as long as this copyright message is kept intact.
	
***********************************************************************************************/




var activeCrumb = false;
var BreadCrumbLeftPos = false;
var BreadCrumbWidth = false;
var BreadCrumbObj = false;
var maxCrumbXPos = false;
var minCrumbXPos = false;
var crumbslideSpeed = 0;
function startCrumbSlide(e) {
  if (document.all) e = event;
  var id = this.id;
    if (this.id == 'arrowcrumb_right') {
        var test = (e.clientX - this.offsetLeft);
        crumbslideSpeedMultiply = Math.floor(test / 5);
        crumbslideSpeed = -1 * crumbslideSpeedMultiply;
        crumbslideSpeed = Math.max(-10, crumbslideSpeed);
       // crumbSlide();
    } else {
    var test = (e.clientX - this.offsetLeft);
    var anothertest = Math.floor(test / 5);
        crumbslideSpeedMultiply = 10 - anothertest;
        crumbslideSpeed = 1 * crumbslideSpeedMultiply;
        crumbslideSpeed = Math.min(10, crumbslideSpeed);
        if (crumbslideSpeed < 0) crumbslideSpeed = 10;
        //crumbSlide();
    }
}

function releaseCrumbSlide() {
  var id = this.id;
    crumbslideSpeed = 0;
}

function crumbSlide() {
  if (crumbslideSpeed != 0) {
        var leftPos = BreadCrumbObj.offsetLeft;
        leftPos = leftPos / 1 + crumbslideSpeed;
        if (leftPos > maxCrumbXPos) {
            leftPos = maxCrumbXPos;
            crumbslideSpeed = 0;
            document.getElementById('arrowcrumb_left').style.display = 'none';
            document.getElementById('arrowcrumb_right').style.display = '';
            
        }
        if (leftPos < minCrumbXPos) {
            leftPos = minCrumbXPos;
            crumbslideSpeed = 0;
            document.getElementById('arrowcrumb_left').style.display = '';
            document.getElementById('arrowcrumb_right').style.display = 'none';
        }

        BreadCrumbObj.style.left = leftPos + 'px';
    }
    setTimeout('crumbSlide()', 20);

}



function initBreadCrumb() {
    if (document.getElementById('arrowcrumb_left') != null) {
        document.getElementById('arrowcrumb_left').onmousedown = startCrumbSlide;
        document.getElementById('arrowcrumb_left').onmouseup = releaseCrumbSlide;
        document.getElementById('arrowcrumb_right').onmousedown = startCrumbSlide;
        document.getElementById('arrowcrumb_right').onmouseup = releaseCrumbSlide;

        BreadCrumbObj = document.getElementById('breadcrumbs');
        BreadCrumbLeftPos = BreadCrumbObj.offsetLeft;
        BreadCrumbWidth = document.getElementById('mainbreadcrumb').offsetWidth - 80;
        maxCrumbXPos = BreadCrumbObj.offsetLeft;
        minCrumbXPos = BreadCrumbWidth - document.getElementById('slideEnd').offsetLeft;
        var breadcrumblinks = BreadCrumbObj.getElementsByTagName('a');
        minCrumbXPos = minCrumbXPos + 85;


        if (minCrumbXPos < document.getElementById('mainbreadcrumb').offsetLeft) {
            BreadCrumbObj.style.left = (minCrumbXPos) + 'px';
            document.getElementById('arrowcrumb_right').style.display = 'none';
            crumbSlide();
        }
        else {
            document.getElementById('arrowcrumb_left').style.display = 'none';
            document.getElementById('arrowcrumb_right').style.display = 'none';
        }

    }
}
    $(document).ready(initBreadCrumb);

    /***********************************************************************************************
	
Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com
	
UPDATE LOG:
	
March, 10th, 2006 : Added support for a message while large image is loading
	
Get this and other scripts at www.dhtmlgoodies.com
	
You can use this script freely as long as this copyright message is kept intact.
	
***********************************************************************************************/

    var activeImage = false;
    var imageGalleryLeftPos = false;
    var imageGalleryWidth = false;
    var imageGalleryObj = false;
    var maxGalleryXPos = false;
    var slideSpeed = 0;
    var imageGalleryCaptions = new Array();
    var leftPos = 0;
    function startSlide(e) {
        if (document.all) e = event;
        var id = this.id;

        if (this.id == 'arrow_right') {
            slideSpeed = -((imageGalleryWidth + 80) + 2);
            gallerySlide();


        } else {
     
         
            slideSpeed = (imageGalleryWidth + 80) + 2;
            if (slideSpeed < 0) slideSpeed = (imageGalleryWidth + 80) + 2;

            gallerySlide();
        }
    }

    function gallerySlide() {

        if (slideSpeed != 0) {

            leftPos = leftPos + slideSpeed;

            //leftPos = leftPos - 5;

            if (leftPos > maxGalleryXPos) {
                leftPos = maxGalleryXPos;

                slideSpeed = 0;

            }
            if (leftPos < minGalleryXPos) {
                leftPos = minGalleryXPos;

                slideSpeed = 0;

            }

            imageGalleryObj.style.left = leftPos + 'px';
        }
        setTimeout('gallerySlide()', 20);
        slideSpeed = 0;

    }

    function isEven(value) {
        if (value % 2 == 0)
            return true;
        else
            return false;
    }


    function initSlideShow() {
        if ((document.getElementById('arrow_left') != null) && (document.getElementById('arrow_right') != null)) {
     


            imageGalleryObj = document.getElementById('thumbnails');

            var divs = imageGalleryObj.getElementsByTagName('DIV');
            var numDivs = 0;
            for (var no = 0; no < divs.length; no++) {


                numDivs++;


            }
           numDivs = numDivs - 1;

  

           var thumbnaillength = divs[numDivs].offsetWidth + 6;
           var Gallwidth = divs[numDivs].offsetLeft;
                Gallwidth = (Gallwidth / 2) + thumbnaillength;
            imageGalleryObj.style.width = Gallwidth + "px";
           
            imageGalleryLeftPos = imageGalleryObj.offsetLeft;
            imageGalleryWidth = document.getElementById('mainthumbnails').offsetWidth - 80;
            if (Gallwidth > (imageGalleryWidth + 80)) {
                document.getElementById('arrow_left').onmousedown = startSlide;

                document.getElementById('arrow_right').onmousedown = startSlide;

            }
            maxGalleryXPos = imageGalleryObj.offsetLeft + 3;


      
                var divsas = imageGalleryObj.getElementsByTagName('DIV');
                var OffsetLeft = divsas[numDivs].offsetLeft;
                minGalleryXPos = imageGalleryWidth - (OffsetLeft - 3);
     
            minGalleryXPos = minGalleryXPos - 36;

        }
    }
    $(document).ready(initSlideShow);

