// jQuery Plugins for SV - 25Jan10
/*
 * Facebox (for jQuery)
 * version: 1.2 (05/05/2008)
 * @requires jQuery v1.2 or later
 *
 * Examples at http://famspam.com/facebox/
 *
 * Licensed under the MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2007, 2008 Chris Wanstrath [ chris@ozmm.org ]
 */
(function($) {
$.facebox = function(data, klass) {
$.facebox.loading()

if (data.ajax) fillFaceboxFromAjax(data.ajax)
else if (data.image) fillFaceboxFromImage(data.image)
else if (data.div) fillFaceboxFromHref(data.div)
else if ($.isFunction(data)) data.call($)
else $.facebox.reveal(data, klass)
}
$.extend($.facebox, {
settings: {
opacity      : .75,
overlay      : true,
loadingImage : '/template/facebox/loading.gif',
closeImage   : '/template/facebox/closelabel.gif',
imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
faceboxHtml  : '\
<div id="facebox" style="display:none;"> \
<div class="popup"> \
<table> \
<tbody> \
<tr> \
<td class="body"> \
<div class="footer"> \
<a href="#" class="close"> \
<img src="/template/facebox/closelabel.gif" title="close" class="close_image" /> \
</a> \
</div> \
<div class="content"> \
</div> \
</td> \
</tr> \
</tbody> \
</table> \
</div> \
</div>'
},

loading: function() {
init()
if ($('#facebox .loading').length == 1) return true
showOverlay()

$('#facebox .content').empty()
$('#facebox .body').children().hide().end().
append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')

$('#facebox').css({
top:	getPageScroll()[1] + (getPageHeight() / 10),
left:	385.5
}).show()

$(document).bind('keydown.facebox', function(e) {
if (e.keyCode == 27) $.facebox.close()
return true
})
$(document).trigger('loading.facebox')
},

reveal: function(data, klass) {
$(document).trigger('beforeReveal.facebox')
if (klass) $('#facebox .content').addClass(klass)
$('#facebox .content').append(data)
$('#facebox .loading').remove()
$('#facebox .body').children().fadeIn('normal')
$('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
$(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
},

close: function() {
$(document).trigger('close.facebox')
return false
}
})

$.fn.facebox = function(settings) {
init(settings)

function clickHandler() {
$.facebox.loading(true)
var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
if (klass) klass = klass[1]

fillFaceboxFromHref(this.href, klass)
return false
}

return this.click(clickHandler)
}
function init(settings) {
if ($.facebox.settings.inited) return true
else $.facebox.settings.inited = true

$(document).trigger('init.facebox')
makeCompatible()

var imageTypes = $.facebox.settings.imageTypes.join('|')
$.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')

if (settings) $.extend($.facebox.settings, settings)
$('body').append($.facebox.settings.faceboxHtml)

var preload = [ new Image(), new Image() ]
preload[0].src = $.facebox.settings.closeImage
preload[1].src = $.facebox.settings.loadingImage

$('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
preload.push(new Image())
preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
})

$('#facebox .close').click($.facebox.close)
$('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
}
  
// getPageScroll() by quirksmode.com
function getPageScroll() {
var xScroll, yScroll;
if (self.pageYOffset) {
yScroll = self.pageYOffset;
xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
yScroll = document.documentElement.scrollTop;
xScroll = document.documentElement.scrollLeft;
} else if (document.body) {// all other Explorers
yScroll = document.body.scrollTop;
xScroll = document.body.scrollLeft;	
}
return new Array(xScroll,yScroll) 
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
var windowHeight
if (self.innerHeight) {	// all except Explorer
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowHeight = document.body.clientHeight;
}	
return windowHeight
}

// Backwards compatibility
function makeCompatible() {
var $s = $.facebox.settings

$s.loadingImage = $s.loading_image || $s.loadingImage
$s.closeImage = $s.close_image || $s.closeImage
$s.imageTypes = $s.image_types || $s.imageTypes
$s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
}
function fillFaceboxFromHref(href, klass) {
if (href.match(/#/)) {
var url    = window.location.href.split('#')[0]
var target = href.replace(url,'')
$.facebox.reveal($(target).clone().show(), klass)
} else if (href.match($.facebox.settings.imageTypesRegexp)) {
fillFaceboxFromImage(href, klass)
} else {
fillFaceboxFromAjax(href, klass)
}
}

function fillFaceboxFromImage(href, klass) {
var image = new Image()
image.onload = function() {
$.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
}
image.src = href
}

function fillFaceboxFromAjax(href, klass) {
$.get(href, function(data) { $.facebox.reveal(data, klass) })
}

function skipOverlay() {
return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 
}

function showOverlay() {
if (skipOverlay()) return

if ($('facebox_overlay').length == 0) 
$("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

$('#facebox_overlay').hide().addClass("facebox_overlayBG")
.css('opacity', $.facebox.settings.opacity)
.click(function() { $(document).trigger('close.facebox') })
.fadeIn(200)
return false
}

function hideOverlay() {
if (skipOverlay()) return

$('#facebox_overlay').fadeOut(200, function(){
$("#facebox_overlay").removeClass("facebox_overlayBG")
$("#facebox_overlay").addClass("facebox_hide") 
$("#facebox_overlay").remove()
})
    
return false
}
$(document).bind('close.facebox', function() {
$(document).unbind('keydown.facebox')
$('#facebox').fadeOut(function() {
$('#facebox .content').removeClass().addClass('content')
hideOverlay()
$('#facebox .loading').remove()})})})(jQuery);



// Expand Div + Change text
function showdiv(divid){
document.getElementById(divid).style.display = (document.getElementById(divid).style.display == "none") ? "" : "none";
}

function changedivhtml(thisdiv, newhtml){
document.getElementById(thisdiv).innerHTML = newhtml;
}

// Hide Div
function hidediv(divid){
try
{
document.getElementById(divid).style.display = "none";
}
catch(e)
 {
 }
}

function unhidediv(divid){
try
{
document.getElementById(divid).style.display = "";
}
catch(e)
{
}
}

// Quick Change Class Function //
function changeClass(str1, str2, str3){
	document.getElementById(str1).className = str2
	if (str3) {
		document.getElementById(str3).className = '';
	}
}

function ShowTabDiv(DivName) {
	hidediv('tabcontent1');
	hidediv('tabcontent2');
	hidediv('tabcontent3');
	hidediv('tabcontent4');
	if (document.getElementById('tablink1').className =='currenttab') {
		document.getElementById('tablink1').className ='othertab';
	};
	if (document.getElementById('tablink2').className =='currenttab') {
		document.getElementById('tablink2').className ='othertab';
	};
	if (document.getElementById('tablink3').className =='currenttab') {
		document.getElementById('tablink3').className ='othertab';
	};
	if (document.getElementById('tablink4').className =='currenttab') {
		document.getElementById('tablink4').className ='othertab';
	};	
	unhidediv('tabcontent'+DivName);
	document.getElementById('tablink'+DivName).className ='currenttab';
}

/*
 * jQuery Expander plugin
 * Version 0.4  (12/09/2008)
 * @requires jQuery v1.1.1+
 *
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * From http://plugins.learningjquery.com/expander/jquery.expander.js
 */
(function($) {

$.fn.expander = function(options) {

var opts = $.extend({}, $.fn.expander.defaults, options);
var delayedCollapse;
return this.each(function() {
var $this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
var cleanedTag, startTags, endTags;	
var allText = $this.html();
var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,'');
startTags = startText.match(/<\w[^>]*>/g);
if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}
   	  
if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {
startText = startText.slice(0,startText.lastIndexOf('<'));
}
var endText = allText.slice(startText.length);
// swap temporary element for this one
$("span.hidedetails").addClass("details");
$("span.hidedetails").removeClass("hidedetails");
// create necessary expand/collapse elements if they don't already exist
if (!$('span.details', this).length) {
// end script if text length isn't long enough.
if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; }
// otherwise, continue...    
if (endText.indexOf('</') > -1) {
endTags = endText.match(/<(\/)?[^>]*>/g);
for (var i=0; i < endTags.length; i++) {

if (endTags[i].indexOf('</') > -1) {
var startTag, startTagExists = false;
for (var j=0; j < i; j++) {
startTag = endTags[j].slice(0, endTags[j].indexOf(' ')).replace(/(\w)$/,'$1>');
if (startTag == rSlash(endTags[i])) {
  startTagExists = true;
}
}              
if (!startTagExists) {
startText = startText + endTags[i];
var matched = false;
for (var s=startTags.length - 1; s >= 0; s--) {
  if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) 
  && matched == false) {
    cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];
    matched = true;
  }
};
}
}
}

endText = cleanedTag && cleanedTag + endText || endText;
}
$this.html([
startText,
'<span class="readmore">',
o.expandPrefix,
'<a href="#">',
o.expandText,
'</a>',
'</span>',
'<span class="details">',
endText,
'</span>'
].join('')
);
}
var $thisDetails = $('span.details', this),
$readMore = $('span.readmore', this);
$thisDetails.hide();
$readMore.find('a').click(function() {
$readMore.hide();

if (o.expandEffect === 'show' && !o.expandSpeed) {
o.beforeExpand($this);
$thisDetails.show();
o.afterExpand($this);
delayCollapse(o, $thisDetails);
} else {
o.beforeExpand($this);
$thisDetails[o.expandEffect](o.expandSpeed, function() {
$thisDetails.css({zoom: ''});
o.afterExpand($this);
delayCollapse(o, $thisDetails);
});
}
return false;
});
if (o.userCollapse) {
$this
.find('span.details').append('<span class="recollapse">' + o.userCollapsePrefix + '<a href="#" class="recollapse">' + o.userCollapseText + '</a></span>');
$this.find('span.recollapse a').click(function() {
clearTimeout(delayedCollapse);
var $detailsCollapsed = $(this).parents('span.details');
reCollapse($detailsCollapsed);
o.onCollapse($this, true);
return false;
});
}
});
function reCollapse(el) {
el.hide();
var $readMore= $('span.readmore', el.parent());
$readMore.show();
}
function delayCollapse(option, $collapseEl) {
if (option.collapseTimer) {
delayedCollapse = setTimeout(function() {  
reCollapse($collapseEl);
option.onCollapse($collapseEl.parent(), false);
},
option.collapseTimer
);
}
}
function rSlash(rString) {
return rString.replace(/\//,'');
}    
};
$.fn.expander.defaults = {
slicePoint: 300,
widow: 10,
expandText: 'view info',
expandPrefix: '&hellip; ',
collapseTimer: 0,
expandEffect: 'fadeIn',
expandSpeed: '',
userCollapse: true,
userCollapseText: 'close',
userCollapsePrefix: '<br>',
beforeExpand: function($thisEl) {},
afterExpand: function($thisEl) {},
onCollapse: function($thisEl, byUser) {}
};
})(jQuery);
