/*
	jQuery - siteFeature Plugin
	@copyright Michael Kafka - http://www.makfak.com
	@version 2.1
*/
(function($){

	$.fn.siteFeature = function(options) {
		var opts = $.extend({}, $.fn.siteFeature.defaults, options);

		return this.each(function(i) {
			obj = $(this);
			var settings = {};
				settings.which = i;
			// contains all DOM traversal and manipulation
			createFeature(opts,settings);
			// configures the Feature based on the options
			customizeFeature(opts,settings);
			// binds all associated events
			eventFeature(opts,settings);
		}); 
    }; // end $.fn.siteFeature

	// SiteFeature Customizable Options
	$.fn.siteFeature.defaults = {
		outputElementId: 'siteFeature',			// this is the ID given to the container div generated by siteFeature
		txtBoxIdPrefix: 'txtBox',				// creates the naming convention for the TextBox (ie: txtBoxContainer) 
		imgBgIdPrefix: 'imgBg',					// creates the naming convention for the ImageBackgounds (ie: imgBgContainer)
		tabIdPrefix: 'tab',						// creates the naming convention for the Tabs (ie: tabContainer)
		titleText: 'h3',						// identifies the Title Text for manipulation
		containerWidth: '915px',				// sets the generated Container's width
		containerHeight: '265px',				// sets the generated Container's height
		imgWidth: '690px',						// sets the width of the ImageBox/TextBox section. When subtracted from the Container's width - yields the Tabs width.
		tabsLocation: 'left',					// sets position of the Tabs (relative to the Image Box)
		tabBgImg: 'images/arrow-left.png',		// relative path for Image used as Highlighted Tab background (ie: the arrow)
		tabBgImgIE6: 'images/arrow-left.gif',	// relative path for Image used by IE6 (to prevent PNG alpha issues). Leave blank ('') or set to null to uses the same image (and to teach IE6 users a lesson).
		tabControl: 'click',					// sets the event that activates the tab change: 'click', 'hover'
		tabLock: 4,								// sets the number of tabs before the overflow (int / null)
		txtBoxWidth: '215px',					// sets the width of the Vertical TextBox
		txtBoxHorizontalHeight: '90px',			// sets the height of the Horizontal TextBox
		txtBoxOpacity: .7,						// sets the opcaity of the TextBox background (color set in CSS - default is #000000)
		activeTabIsLink: true,					// determines if the the Highlighted Tab is a link to said Tab's default destination (the original href)
		activeWindowIsLink: false,				// determines if the current ImageBackground and TextBox are links to the Tab's default destination (the original href)
		animateInOnLoad: true,					// determines if the Tab, ImageBackground, and TextBox animate In on page load or simply appear
		txtBoxAnimateInType: 'slideLeft',		// sets animation In type for vertical TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateOutType: 'slideRight',		// sets animation Out type for vertical TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateHorzAlt: true,				// allows horizontal txtBoxes to animate in/out differently
		txtBoxAnimateInHorzType: 'slideUp',		// sets animation In type for horizontal TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateOutHorzType: 'slideDown',	// sets animation Out type for horizontal TextBoxes: 'blink', 'fade', 'slideUp', 'slideDown', 'slideLeft', 'slideRight'
		txtBoxAnimateInDuration: 1,			// sets the duration for TextBox In animations (in milliseconds)
		txtBoxAnimateOutDuration: 1,			// sets the duration for TextBox Out animations (in milliseconds)
		txtBoxPauseBetweenInOut: 1,			// sets the duration for the pause between the current TextBox animating Out and the new TextBox animating In ('0' for no delay) (in milliseconds)
		cols: 10,								// sets the number of columns used in the bgImg transitions
		rows: 5,								// sets the number of rows used in the bgImg transitions
		imgBgsAnimationDuration: 300,			// sets the duration for ImageBackground In animations (in milliseconds)
		imgBgsAnimateOutDuration: 300,			// sets the duration for ImageBackground Out animations (in milliseconds)
		imgBgsAnimationType: 'cycle',			// sets animation type: 'fade', 'wave', 'crash', 'curtain', 'zipper', 'fountain', 'cascade', 'dribble', 'checker', 'enterTheDragon', 'random', 'cycle'
		imgBgsAnimationList: ['fade', 'wave', 'crash', 'curtain', 'zipper', 'fountain', 'cascade', 'dribble', 'checker', 'enterTheDragon'],
		imgBgAnimationDirection: 'left',		// sets the start position of the transition: 'left', 'right', 'random'
		tabsAnimateInDuration: 100,				// sets the duration for Tab In animations (in milliseconds)
		tabsAnimateWidth: '+=20',				// sets the relative pixel width difference to be animated (to reveal the arrow)
		autoPlay: true,						// determines if the tabs cycle automatically
		autoPlayInterval: 8000,					// sets the autoPlay interval
		pauseOnHover: true,						// pause the autoPlay when hovering on siteFeature
		ieEnableFilters: false,					// adds a function to the end of every animation to remove IE filters (re-enables transparency)(boolean - true/false)
		endCreateFunction: null					// creates a userdefined Callback (with access to all plugin Options) that fires after everything has been written to the DOM but before events are bound.
	}; // end $.fn.siteFeature.defaults
	
   $.fn.siteFeatureTxtBoxAnimationsOut = function (a) {
        if ($(this).hasClass('horizontal') && a.txtBoxAnimateHorzAlt) {
            var b = a.txtBoxAnimateOutType;
            a.txtBoxAnimateOutType = a.txtBoxAnimateOutHorzType
        }
        if (a.txtBoxAnimateOutType == 'blink') {
            $(this).css({
                'opacity': '0',
                'display': 'none'
            })
        }
        if (a.txtBoxAnimateOutType == 'fade') {
            $(this).animate({
                'opacity': '0'
            }, a.txtBoxAnimateOutDuration, function () {
                $(this).css({
                    'display': 'none'
                })
            })
        }
        if (a.txtBoxAnimateOutType == 'slideUp') {
            if (!$(this).hasClass('horizontal')) {
                $(this).stop().animate({
                    'marginTop': '-' + a.containerHeight
                }, a.txtBoxAnimateOutDuration, function () {
                    $(this).css({
                        'opacity': '0',
                        'margin-top': '0',
                        'display': 'none'
                    })
                })
            } else {
                $(this).css({
                    'opacity': '1'
                }).slideUp(a.txtBoxAnimateOutDuration, function () {
                    $(this).css({
                        'opacity': '0',
                        'display': 'none'
                    })
                })
            }
        }
        if (a.txtBoxAnimateOutType == 'slideDown') {
            $(this).stop().animate({
                'marginTop': a.containerHeight
            }, a.txtBoxAnimateOutDuration, function () {
                $(this).css({
                    'opacity': '0',
                    'margin-top': '0',
                    'display': 'none'
                })
            })
        }
        if (a.txtBoxAnimateOutType == 'slideLeft') {
            if (a.tabsLocation == 'left') {
                if (!$(this).hasClass('horizontal')) {
                    $(this).css({
                        'right': 'auto',
                        'left': (parseInt(a.imgWidth) - parseInt(a.txtBoxWidth))
                    }).children().each(function () {
                        $(this).css({
                            'width': $(this).width()
                        })
                    }).end().css({
                        'opacity': '1'
                    }).stop().animate({
                        'width': '0'
                    }, a.txtBoxAnimateOutDuration, function () {
                        $(this).css({
                            'opacity': '0',
                            'width': a.txtBoxWidth,
                            'display': 'none'
                        })
                    })
                } else {
                    $(this).children().each(function () {
                        $(this).css({
                            'width': $(this).width()
                        })
                    }).end().css({
                        'opacity': '1'
                    }).stop().animate({
                        'left': '-' + a.imgWidth
                    }, a.txtBoxAnimateOutDuration, function () {
                        $(this).css({
                            'opacity': '0',
                            'left': '0',
                            'display': 'none'
                        })
                    })
                }
            } else {
                $(this).css({
                    'right': 'auto',
                    'left': '0'
                }).stop().animate({
                    'left': '-' + a.imgWidth
                }, a.txtBoxAnimateOutDuration, function () {
                    $(this).css({
                        'opacity': '0',
                        'left': '0',
                        'display': 'none'
                    })
                })
            }
        }
        if (a.txtBoxAnimateOutType == 'slideRight') {
            if (a.tabsLocation == 'left') {
                if (!$(this).hasClass('horizontal')) {
                    $(this).css({
                        'opacity': '1',
                        'left': 'auto',
                        'right': '0'
                    }).stop().animate({
                        'right': '-' + a.txtBoxWidth
                    }, a.txtBoxAnimateOutDuration, function () {
                        $(this).css({
                            'opacity': '0',
                            'right': '0',
                            'display': 'none'
                        })
                    })
                } else {
                    $(this).css({
                        'opacity': '1',
                        'left': 'auto'
                    }).stop().animate({
                        'right': '-' + a.imgWidth
                    }, a.txtBoxAnimateOutDuration, function () {
                        $(this).css({
                            'opacity': '0',
                            'right': '0',
                            'display': 'none'
                        })
                    })
                }
            } else {
                if (!$(this).hasClass('horizontal')) {
                    $(this).css({
                        'left': '0px'
                    }).stop().animate({
                        'left': '-' + a.txtBoxWidth
                    }, a.txtBoxAnimateOutDuration, function () {
                        $(this).css({
                            'opacity': '0',
                            'display': 'none',
                            'left': '0px'
                        })
                    })
                } else {
                    $(this).css({
                        'left': '0px'
                    }).stop().animate({
                        'left': '-' + a.imgWidth
                    }, a.txtBoxAnimateOutDuration, function () {
                        $(this).css({
                            'opacity': '0',
                            'display': 'none',
                            'left': '0px'
                        })
                    })
                }
            }
        }
        if ($(this).hasClass('horizontal') && a.txtBoxAnimateHorzAlt) {
            a.txtBoxAnimateOutType = b
        }
        return this
    };
    $.fn.siteFeatureTxtBoxAnimationsIn = function (a) {
        if ($(this).hasClass('horizontal') && a.txtBoxAnimateHorzAlt) {
            var b = a.txtBoxAnimateInType;
            a.txtBoxAnimateInType = a.txtBoxAnimateInHorzType
        }
        if (a.txtBoxAnimateInType == 'blink') {
            $(this).animate({
                'opacity': '0'
            }, a.txtBoxPauseBetweenInOut, function () {
                $(this).css({
                    'opacity': '1',
                    'display': 'block'
                })
            })
        }
        if (a.txtBoxAnimateInType == 'fade') {
            $(this).animate({
                'opacity': '0'
            }, a.txtBoxPauseBetweenInOut, function () {
                $(this).css({
                    'display': 'block'
                }).animate({
                    'opacity': '1'
                }, a.txtBoxAnimateInDuration, function () {
                    ieStyleFilterCleanup($(this), a)
                })
            })
        }
        if (a.txtBoxAnimateInType == 'slideUp') {
            $(this).animate({
                'opacity': '0'
            }, a.txtBoxPauseBetweenInOut, function () {
                $(this).css({
                    'display': 'block',
                    'opacity': '1',
                    'margin-top': a.containerHeight
                }).animate({
                    'marginTop': '0'
                }, a.txtBoxAnimateInDuration, function () {
                    ieStyleFilterCleanup($(this), a)
                })
            })
        }
        if (a.txtBoxAnimateInType == 'slideDown') {
            if (!$(this).hasClass('horizontal')) {
                $(this).animate({
                    'opacity': '0'
                }, a.txtBoxPauseBetweenInOut, function () {
                    $(this).css({
                        'display': 'block',
                        'opacity': '1',
                        'margin-top': '-' + a.containerHeight
                    }).animate({
                        'marginTop': '0'
                    }, a.txtBoxAnimateInDuration, function () {
                        ieStyleFilterCleanup($(this), a)
                    })
                })
            } else {
                $(this).animate({
                    'opacity': '0'
                }, a.txtBoxPauseBetweenInOut, function () {
                    $(this).css({
                        'display': 'block',
                        'opacity': '1'
                    }).slideUp(0).slideDown(a.txtBoxAnimateInDuration, function () {
                        ieStyleFilterCleanup($(this), a)
                    })
                })
            }
        }
        if (a.txtBoxAnimateInType == 'slideLeft') {
            if (a.tabsLocation == 'left') {
                if (!$(this).hasClass('horizontal')) {
                    $(this).animate({
                        'opacity': '0'
                    }, a.txtBoxPauseBetweenInOut, function () {
                        $(this).css({
                            'display': 'block',
                            'opacity': '1',
                            'right': '-' + a.txtBoxWidth
                        }).animate({
                            'right': '0'
                        }, a.txtBoxAnimateInDuration, function () {
                            ieStyleFilterCleanup($(this), a)
                        })
                    })
                } else {
                    $(this).animate({
                        'opacity': '0'
                    }, a.txtBoxPauseBetweenInOut, function () {
                        $(this).css({
                            'display': 'block',
                            'opacity': '1',
                            'left': 'auto',
                            'right': '-' + a.imgWidth
                        }).animate({
                            'right': '0'
                        }, a.txtBoxAnimateInDuration, function () {
                            ieStyleFilterCleanup($(this), a)
                        })
                    })
                }
            } else {
                if (!$(this).hasClass('horizontal')) {
                    $(this).animate({
                        'opacity': '0'
                    }, a.txtBoxPauseBetweenInOut, function () {
                        $(this).css({
                            'display': 'block'
                        }).children().each(function () {
                            $(this).css({
                                'width': $(this).width()
                            })
                        }).end().css({
                            'display': 'block',
                            'opacity': '1',
                            'width': '0',
                            'left': 'auto',
                            'right': parseInt(a.imgWidth) - parseInt(a.txtBoxWidth)
                        }).animate({
                            'width': a.txtBoxWidth
                        })
                    })
                } else {
                    $(this).animate({
                        'opacity': '0'
                    }, a.txtBoxPauseBetweenInOut, function () {
                        $(this).css({
                            'display': 'block',
                            'opacity': '1',
                            'left': 'auto',
                            'right': '-' + a.imgWidth
                        }).animate({
                            'right': '0'
                        }, a.txtBoxAnimateInDuration, function () {
                            ieStyleFilterCleanup($(this), a)
                        })
                    })
                }
            }
        }
        if (a.txtBoxAnimateInType == 'slideRight') {
            if (a.tabsLocation == 'left') {
                if (!$(this).hasClass('horizontal')) {
                    $(this).animate({
                        'opacity': '0'
                    }, a.txtBoxPauseBetweenInOut, function () {
                        $(this).css({
                            'display': 'block',
                            'right': 'auto',
                            'left': (parseInt(a.imgWidth) - parseInt(a.txtBoxWidth))
                        }).children().each(function () {
                            $(this).css({
                                'width': $(this).width()
                            })
                        }).end().css({
                            'opacity': '1',
                            'width': '0'
                        }).animate({
                            'width': a.txtBoxWidth
                        }, a.txtBoxAnimateInDuration, function () {
                            ieStyleFilterCleanup($(this), a)
                        })
                    })
                } else {
                    $(this).animate({
                        'opacity': '0'
                    }, a.txtBoxPauseBetweenInOut, function () {
                        $(this).css({
                            'display': 'block',
                            'right': 'auto',
                            'left': '-' + a.imgWidth
                        }).children().each(function () {
                            $(this).css({
                                'width': $(this).width()
                            })
                        }).end().css({
                            'opacity': '1'
                        }).animate({
                            'left': '0'
                        }, a.txtBoxAnimateInDuration, function () {
                            ieStyleFilterCleanup($(this), a)
                        })
                    })
                }
            } else {
                $(this).animate({
                    'opacity': '0'
                }, a.txtBoxPauseBetweenInOut, function () {
                    $(this).css({
                        'display': 'block',
                        'opacity': '1',
                        'left': '-' + a.imgWidth
                    }).animate({
                        'left': '0'
                    }, a.txtBoxAnimateInDuration, function () {
                        ieStyleFilterCleanup($(this), a)
                    })
                })
            }
        }
        if ($(this).hasClass('horizontal') && a.txtBoxAnimateHorzAlt) {
            a.txtBoxAnimateInType = b
        }
        return this
    };
    $.fn.siteFeatureImgAnimations = function (a, b, c) {
        b.imgIsAnimating = true;
        a.width = parseInt(a.imgWidth);
        a.height = parseInt(a.containerHeight);
        $imgs = $(this);
        if (a.imgBgsAnimationType == 'random' || a.animationMemory == 'random') {
            a.animationMemory = 'random';
            var d = a.imgBgsAnimationList.slice(0);
            d.splice(d.indexOf(a.imgBgsAnimationType), 1);
            d.sort(function () {
                return 0.5 - Math.random()
            });
            a.imgBgsAnimationType = d[0]
        }
        if (a.imgBgsAnimationType == 'cycle' || a.animationMemory == 'cycle') {
            a.animationMemory = 'cycle';
            for (i = 0; i < a.imgBgsAnimationList.length; i++) {
                if (a.imgBgsAnimationList[i] == a.imgBgsAnimationType) {
                    a.currentAni = i;
                    break
                } else {
                    a.currentAni = -1
                }
            }
            if (a.currentAni < 0 || a.currentAni == a.imgBgsAnimationList.length - 1) {
                a.currentAni = 0
            } else {
                a.currentAni++
            }
            a.imgBgsAnimationType = a.imgBgsAnimationList[a.currentAni]
        }
        if (a.imgBgsAnimationType == 'enterTheDragon') {
            $target = $(this).filter('.selected');
            $current = $(this).filter(c)
        } else {
            $target = $(this).filter(c);
            $current = $(this).filter('.selected')
        }
        $copy = $target.clone();
        if (a.imgBgAnimationDirection == 'random') {
            a.directionList = ['left', 'right'];
            a.directionMemory = a.directionList.sort(function () {
                return 0.5 - Math.random()
            })[0]
        } else {
            a.directionMemory = a.imgBgAnimationDirection
        }
        var e = [];
        var f = [];
        var g = [];
        var h = parseInt(a.width / a.cols);
        var k = parseInt(a.height / a.rows);
        var l = a.width - (h * a.cols);
        var m = a.height - (k * a.rows);
        var n = 0;
        var o = 0;
        var p = 1;
        var q = 0;
        var r = a.imgBgsAnimationDuration / 8;
        var s = 1;
        for (i = 0; i < a.cols; i++) {
            if (l > 0) {
                tcolWidth = h + 1;
                l--
            } else {
                tcolWidth = h
            }
            var t = $target.clone().show().attr({
                'id': ''
            }).addClass('col-' + i).css({
                'background-position': -n + 'px top',
                'width': tcolWidth + "px",
                'height': a.height + "px",
                'float': 'left',
                'position': 'absolute',
                'left': n
            });
            if (a.imgBgsAnimationType == 'wave' || a.imgBgsAnimationType == 'cascade') {
                t.css({
                    'height': 0
                })
            }
            if (a.imgBgsAnimationType == 'fall') {
                t.css({
                    'top': a.height * -1
                })
            }
            if (a.imgBgsAnimationType == 'curtain') {
                t.data('width', t.css('width')).css({
                    'width': 0
                })
            }
            if (a.imgBgsAnimationType == 'zipper') {
                if ((i + 1) % 2 == 0) {
                    t.css({
                        'top': a.height
                    })
                } else {
                    t.css({
                        'top': a.height * -1
                    })
                }
            }
            if (a.imgBgsAnimationType == 'fountain') {
                t.css({
                    'top': a.height
                })
            }
            if (a.imgBgsAnimationType == 'crash' || a.imgBgsAnimationType == 'dribble') {
                t.css({
                    'top': a.height * -1
                })
            }
            if (a.imgBgsAnimationType == 'checker') {
                t.css({
                    'background-image': 'none',
                    'opacity': 1
                })
            }
            if (a.imgBgsAnimationType == 'enterTheDragon') {
                $current.css({
                    'opacity': '1',
                    'display': 'block'
                })
            }
            $current.append(t[0]);
            f.push(t);
            if (a.imgBgsAnimationType == 'checker') {
                for (j = 0; j < a.rows; j++) {
                    if (m > 0) {
                        trowHeight = k + 1;
                        m--
                    } else {
                        trowHeight = k
                    }
                    var u = $target.clone().show().attr({
                        'id': ''
                    }).addClass('row-' + i + '-' + j).css({
                        'background-position': -n + 'px ' + -o + 'px',
                        'height': 0,
                        'width': 0,
                        'float': 'left',
                        'position': 'absolute',
                        'left': tcolWidth / 2,
                        'top': o + (trowHeight / 2),
                        'opacity': 1
                    }).data('info', {
                        width: tcolWidth,
                        height: trowHeight,
                        'left': 0,
                        'top': o
                    });
                    $('.col-' + i).append(u[0]);
                    e.push(u[0]);
                    o += trowHeight
                };
                o = 0
            }
            n += tcolWidth
        };
        if (a.imgBgsAnimationType == 'checker') {
            if (a.directionMemory == 'right') {
                var v = a.cols - 1;
                var w = 0;
                var x = a.cols - 1;
                var y = 1
            } else {
                var v = 0;
                var w = 0;
                var x = 0;
                var y = 1
            }
            for (i = 0; i < e.length; i++) {
                if (a.directionMemory == 'right') {
                    if (v < 0) {
                        v = v + y;
                        w = w + y;
                        y++
                    }
                    g[i] = v.toString() + '-' + w.toString();
                    if (v == a.cols - 1 || w >= a.rows - 1) {
                        x--;
                        v = x;
                        w = 0
                    } else {
                        v++;
                        w++
                    }
                } else {
                    if (v > a.cols - 1) {
                        v = v - y;
                        w = w + y;
                        y++
                    }
                    g[i] = v.toString() + '-' + w.toString();
                    if (v == 0 || w >= a.rows - 1) {
                        x++;
                        v = x;
                        w = 0
                    } else {
                        v--;
                        w++
                    }
                }
            };
            f = [];
            $.each(g, function (i) {
                f.push($(e).filter('[class$="-' + this + '"]'))
            })
        }
        if (a.imgBgsAnimationType == 'fountain' || a.imgBgsAnimationType == 'cascade' || a.imgBgsAnimationType == 'dribble' || a.imgBgsAnimationType == 'enterTheDragon') {
            var p = 1;
            var z = f.length / 2;
            for (i = 0; i < f.length; i++) {
                mafs = z - (parseInt((i + 1) / 2) * p);
                g[i] = mafs;
                if (a.imgBgsAnimationType == 'enterTheDragon') {
                    if (i == 0) {
                        p = 0
                    }
                    var A = $(f[parseInt(g[i] - 1)]);
                    var B = (A.width() / 2) * p;
                    if (p < 0) {
                        $ref = A.prev()
                    } else if (p > 0) {
                        $ref = A.next()
                    } else {
                        $ref = A
                    }
                    bgPos = parseInt($ref.css('background-position')) + B;
                    A.data('bgPos-o', A.css('background-position')).css('background-position', bgPos + 'px 0px').data('bgPos-n', bgPos + 'px 0px');
                    if (i == 0) {
                        p = 1
                    }
                }
                p *= -1
            };
            g[a.cols - 1] = 0;
            $.each(f, function () {
                $(this).css('background-position', $(this).data('bgPos-o'))
            })
        }
        if (a.directionMemory == 'right' && a.imgBgsAnimationType != 'checker') {
            f.reverse()
        }
        if (a.imgBgsAnimationType == 'fade') {
            $(this).filter('.selected').animate({
                'opacity': '0'
            }, a.imgBgsAnimationDuration, function () {
                $(this).css({
                    'display': 'none'
                });
                b.imgIsAnimating = false
            }).end().filter(c).css({
                'display': 'block'
            }).animate({
                'opacity': '1'
            }, a.imgBgsAnimationDuration)
        }
        if (a.imgBgsAnimationType == 'wave') {
            $.each(f, function (i) {
                $(this).animate({
                    'letter-spacing': 'normal'
                }, q, function () {
                    $(this).animate({
                        'opacity': '1',
                        'height': a.height
                    }, a.imgBgsAnimationDuration, function () {
                        if ((i + 1) == f.length) {
                            q = 0;
                            $target.css({
                                'opacity': '1'
                            }).show();
                            $current.empty().css({
                                'opacity': '0'
                            }).hide();
                            b.imgIsAnimating = false
                        }
                    })
                });
                q = (q * s + r)
            })
        }
        if (a.imgBgsAnimationType == 'curtain') {
            $.each(f, function (i) {
                $(this).animate({
                    'letter-spacing': 'normal'
                }, q, function () {
                    $(this).animate({
                        'opacity': '1',
                        'width': $(this).data('width')
                    }, a.imgBgsAnimationDuration, function () {
                        if ((i + 1) == f.length) {
                            q = 0;
                            $target.css({
                                'opacity': '1'
                            }).show();
                            $current.empty().css({
                                'opacity': '0'
                            }).hide();
                            b.imgIsAnimating = false
                        }
                    })
                });
                q = (q * s + r)
            })
        }
        if (a.imgBgsAnimationType == 'zipper' || a.imgBgsAnimationType == 'crash') {
            $.each(f, function (i) {
                $(this).animate({
                    'letter-spacing': 'normal'
                }, q, function () {
                    $(this).animate({
                        'opacity': '1',
                        'top': '0'
                    }, a.imgBgsAnimationDuration, function () {
                        if ((i + 1) == f.length) {
                            q = 0;
                            $target.css({
                                'opacity': '1'
                            }).show();
                            $current.empty().css({
                                'opacity': '0'
                            }).hide();
                            b.imgIsAnimating = false
                        }
                    })
                });
                q = (q * s + r)
            })
        }
        if (a.imgBgsAnimationType == 'fountain' || a.imgBgsAnimationType == 'dribble') {
            $.each(g, function (i) {
                f[this].animate({
                    'letter-spacing': 'normal'
                }, q, function () {
                    $(this).animate({
                        'opacity': '1',
                        'top': '0'
                    }, a.imgBgsAnimationDuration, function () {
                        if ((i + 1) == f.length) {
                            q = 0;
                            $target.css({
                                'opacity': '1'
                            }).show();
                            $current.empty().css({
                                'opacity': '0'
                            }).hide();
                            b.imgIsAnimating = false
                        }
                    })
                });
                q = (q * s + r)
            })
        }
        if (a.imgBgsAnimationType == 'cascade') {
            $.each(g, function (i) {
                f[this].animate({
                    'letter-spacing': 'normal'
                }, q, function () {
                    $(this).animate({
                        'opacity': '1',
                        'height': a.height
                    }, a.imgBgsAnimationDuration, function () {
                        if ((i + 1) == f.length) {
                            q = 0;
                            $target.css({
                                'opacity': '1'
                            }).show();
                            $current.empty().css({
                                'opacity': '0'
                            }).hide();
                            b.imgIsAnimating = false
                        }
                    })
                });
                q = (q * s + r)
            })
        }
        if (a.imgBgsAnimationType == 'checker') {
            var r = a.imgBgsAnimationDuration / 25;
            $.each(f, function (i) {
                $(this).animate({
                    'letter-spacing': 'normal'
                }, q, function () {
                    $(this).animate({
                        'width': $(this).data('info').width,
                        'height': $(this).data('info').height,
                        'top': $(this).data('info').top,
                        'left': $(this).data('info').left
                    }, a.imgBgsAnimationDuration, function () {
                        if ((i + 1) == e.length) {
                            q = 0;
                            $target.css({
                                'opacity': '1'
                            }).show();
                            $current.empty().css({
                                'opacity': '0'
                            }).hide();
                            b.imgIsAnimating = false
                        }
                    })
                });
                q = (q * s + r)
            })
        }
        if (a.imgBgsAnimationType == 'enterTheDragon') {
            $target.css({
                'opacity': '0'
            }).hide();
            $.each(g, function (i) {
                f[this].animate({
                    'background-position': f[this].data('bgPos-n')
                }, a.imgBgsAnimationDuration - 100, function () {
                    if (i + 1 == f.length) {
                        g.sort(function () {
                            return 0.5 - Math.random()
                        });
                        $.each(g, function (j) {
                            f[this].animate({
                                'letter-spacing': 'normal'
                            }, q, function () {
                                $(this).animate({
                                    'top': a.containerHeight
                                }, a.imgBgsAnimationDuration, function () {
                                    if (j + 1 == f.length) {
                                        $current.empty();
                                        b.imgIsAnimating = false
                                    }
                                })
                            });
                            q = (q * s + r)
                        })
                    }
                })
            })
        }
        return this
    };

    function ieStyleFilterCleanup(a, b) {
        if ($.browser.msie && b.ieEnableFilters) {
            a.attr('style', a.attr('style').replace(/filter+[^\;]*./gi, '')).children().each(function () {
                $(this).attr('style', $(this).attr('style').replace(/filter+[^\;]*./gi, ''))
            })
        }
    }
    function outerHTML(a) {
        return $('<div>').append(a.eq(0).clone()).html()
    }
    function createFeature(a, b) {
        var c;
        var d = "<div id='" + a.txtBoxIdPrefix + "Container'>";
        var e = "<div id='" + a.imgBgIdPrefix + "Container'>";
        var f = "<div id='" + a.tabIdPrefix + "Container'>";
        if ($.browser.msie && $.browser.version == 6) {
            if (a.tabBgImgIE6 != null || a.tabBgImgIE6 != '') {
                a.tabBgImg = a.tabBgImgIE6
            }
        }
        obj.children().each(function (i) {
            sfcurrent = $(this);
            cloned = sfcurrent.clone().attr({
                id: a.tabIdPrefix + i
            }).children('img').remove().end().wrapInner('<div>').prepend('<span></span>');
            d += outerHTML(cloned);
            e += '<div id="' + a.tabIdPrefix + i + '" style="background-image:url(' + sfcurrent.find('img').attr('src') + '); width:' + a.imgWidth + '; height:' + a.containerHeight + ';"></div>';
            f += '<a href="#' + a.tabIdPrefix + i + '" id="' + a.tabIdPrefix + i + '"><span><span></span><img src="' + a.tabBgImg + '"/></span><h4>' + sfcurrent.find('h3').text() + '</h4><p>' + sfcurrent.find('img').attr('title') + '</p></a>'
        });
        d += "</div>";
        e += "</div>";
        f += "</div>";
        c = (e + d + f);
        obj.empty().attr({
            'id': a.outputElementId,
            'class': a.tabsLocation
        }).css({
            'width': a.containerWidth,
            'height': a.containerHeight
        }).append(c);
        obj.addClass('SF-' + b.which);
        if ($.isFunction(a.endCreateFunction)) {
            a.endCreateFunction.apply(this, [a])
        }
    }
    function customizeFeature(a, b) {
        var c = $('#' + a.txtBoxIdPrefix + 'Container', obj);
        var d = $('#' + a.imgBgIdPrefix + 'Container', obj);
        var e = $('#' + a.tabIdPrefix + 'Container', obj);
        d.css({
            'width': a.imgWidth,
            'height': a.containerHeight
        });
        if (!a.tabLock) {
            b.calcdTabHeight = (parseInt(a.containerHeight) / e.children().length) - (1 + (1 / e.children().length))
        } else {
            b.calcdTabHeight = (parseInt(a.containerHeight) / a.tabLock) - (1 + (1 / e.children().length));
            b.tabTriggers = obj.after('<div id="' + a.outputElementId + '-nav"><a href="#" id="SF-n-prev"><i>prev</i></a><a href="#" id="SF-n-next"><i>next</i></a></div>').next().children();
            b.offsetCount = 0;
            b.tabTriggers.hide().filter('#SF-n-prev').click(function () {
                if (e.children().length - a.tabLock - b.offsetCount != e.children().length - a.tabLock) {
                    e.animate({
                        'top': '+=' + (b.calcdTabHeight + 1)
                    }, 500);
                    b.offsetCount++;
                    return false
                } else {
                    return false
                }
            }).end().filter('#SF-n-next').click(function () {
                if (e.children().length - a.tabLock + b.offsetCount != 0) {
                    e.animate({
                        'top': '-=' + (b.calcdTabHeight + 1)
                    }, 500);
                    b.offsetCount--;
                    return false
                } else {
                    return false
                }
            }).end().hover(function () {
                b.overTriggers = true
            }, function () {
                b.overTriggers = false;
                $(this).animate({
                    'azimuth': '0'
                }, 200, function () {
                    if (!b.overTabs) {
                        b.tabTriggers.fadeOut(350)
                    }
                })
            });
            b.tabTriggers.filter('#SF-n-prev').css({
                'top': obj[0].offsetTop - b.tabTriggers.filter('#SF-n-prev').height() - 1
            }).end().filter('#SF-n-next').css({
                'top': obj[0].offsetTop + obj.height()
            });
            if (a.tabsLocation == 'left') {
                b.tabTriggers.css({
                    'left': obj[0].offsetLeft + ((parseInt(a.containerWidth) - parseInt(a.imgWidth)) / 2) - (b.tabTriggers.filter('#SF-n-prev').width() / 2)
                })
            } else {
                b.tabTriggers.css({
                    'right': obj[0].offsetLeft + ((parseInt(a.containerWidth) - parseInt(a.imgWidth)) / 2) - (b.tabTriggers.filter('#SF-n-prev').width() / 2)
                })
            }
            e.hover(function () {
                b.overTabs = true;
                if (!b.overTriggers) {
                    b.tabTriggers.fadeIn(350)
                }
            }, function () {
                b.overTabs = false;
                $(this).animate({
                    'azimuth': '0'
                }, 200, function () {
                    if (!b.overTriggers) {
                        b.tabTriggers.fadeOut(350)
                    }
                })
            })
        }
        e.children().css({
            'width': (parseInt(a.containerWidth) - parseInt(a.imgWidth)),
            'height': b.calcdTabHeight
        }).children('span').css({
            'width': (parseInt(a.containerWidth) - parseInt(a.imgWidth)),
            'height': b.calcdTabHeight
        }).children('img').css({
            'left': ((a.tabsLocation == 'left') ? parseInt(a.containerWidth) - parseInt(a.imgWidth) : '0')
        }).prev().css({
            'width': (parseInt(a.containerWidth) - parseInt(a.imgWidth))
        });
        c.css({
            'width': a.imgWidth,
            'height': a.containerHeight
        }).children('div:not(.horizontal)').css({
            'width': a.txtBoxWidth,
            'height': '100%'
        }).end().children('div.horizontal').css({
            'width': a.imgWidth,
            'height': a.txtBoxHorizontalHeight,
            'top': (parseInt(a.containerHeight) - parseInt(a.txtBoxHorizontalHeight)),
            'left': '0px'
        }).end().find('div span').css({
            'opacity': a.txtBoxOpacity
        }).next().css({
            'opacity': '1'
        })
    }
    function eventFeature(c, d) {
        var f = obj;
        var g = $('#' + c.txtBoxIdPrefix + 'Container', obj).children();
        var h = $('#' + c.imgBgIdPrefix + 'Container', obj).children();
        var i = $('#' + c.tabIdPrefix + 'Container', obj).children();
        i.click(function (e) {
            if (d.imgIsAnimating) {
                return false
            }
            if (!i.hasClass('selected')) {
                if (c.animateInOnLoad) {
                    g.css({
                        'opacity': '0',
                        'display': 'none'
                    }).filter(this.hash).siteFeatureTxtBoxAnimationsIn(c);
                    h.css({
                        'opacity': '0',
                        'display': 'none'
                    }).filter(this.hash).css({
                        'display': 'block'
                    }).animate({
                        'opacity': '1'
                    }, c.imgBgsAnimationDuration, null);
                    i.filter(this.hash).children('span').animate({
                        'width': c.tabsAnimateWidth
                    }, c.tabsAnimateInDuration, null)
                } else {
                    g.css({
                        'opacity': '0',
                        'display': 'none'
                    }).filter(this.hash).css({
                        'opacity': '1',
                        'display': 'block'
                    });
                    h.css({
                        'opacity': '0',
                        'display': 'none'
                    }).filter(this.hash).css({
                        'opacity': '1',
                        'display': 'block'
                    });
                    i.filter(this.hash).children('span').animate({
                        'width': c.tabsAnimateWidth
                    }, 0, null)
                }
            } else {
                if (!$(this).hasClass('selected')) {
                    var a = this.hash;
                    g.filter('.selected').siteFeatureTxtBoxAnimationsOut(c).end().filter(this.hash).siteFeatureTxtBoxAnimationsIn(c);
                    h.siteFeatureImgAnimations(c, d, this.hash);
                    i.filter('.selected').children('span').css({
                        'width': (parseInt(c.containerWidth) - parseInt(c.imgWidth)),
                        'display': 'none'
                    }).end().end().filter(this.hash).children('span').animate({
                        'width': c.tabsAnimateWidth
                    }, c.tabsAnimateInDuration)
                } else {
                    if (c.activeTabIsLink) {
                        window.location = g.filter(this.hash).find('a').attr('href');
                        return false
                    }
                }
            }
            f.find('.selected').removeClass('selected');
            f.find(this.hash).each(function () {
                $(this).addClass('selected')
            });
            return false
        }).filter(':first').click();
        if ($.browser.msie && $.browser.version == 6) {
            if (g.filter(':first').hasClass('horizontal')) {
                g.filter(':first').css({
                    'height': c.txtBoxHorizontalHeight
                })
            } else {
                g.filter(':first').css({
                    'height': c.containerHeight
                })
            }
        }
        if (c.activeWindowIsLink) {
            $('#' + c.txtBoxIdPrefix + 'Container').css({
                'cursor': 'pointer'
            }).click(function (e) {
                if (e.target.tagName == 'A') {
                    return true
                } else {
                    var a = i.filter('.selected').attr('href');
                    var b = a.lastIndexOf('#');
                    a = a.substring(b, a.length);
                    window.location = g.filter(a).find('a').attr('href');
                    return false
                }
            })
        }
        if (c.autoPlay) {
            SiteFeatureAutoPlayInterval['which' + d.which] = setInterval("siteFeatureAutoPlayer(" + d.which + ")", c.autoPlayInterval);
            if (c.pauseOnHover) {
                obj.hover(function () {
                    clearInterval(SiteFeatureAutoPlayInterval['which' + d.which])
                }, function () {
                    SiteFeatureAutoPlayInterval['which' + d.which] = setInterval("siteFeatureAutoPlayer(" + d.which + ")", c.autoPlayInterval)
                })
            }
        }
        if (c.tabControl == 'hover') {
            i.mouseover(function () {
                if (!$(this).hasClass('selected')) {
                    var a = this.hash;
                    g.filter('.selected').siteFeatureAnimationsOut(c).end().filter(this.hash).siteFeatureAnimationsIn(c);
                    h.filter('.selected').animate({
                        'opacity': '0'
                    }, c.imgBgsAnimationDuration, function () {
                        $(this).css({
                            'display': 'none'
                        })
                    }).end().filter(this.hash).css({
                        'display': 'block'
                    }).animate({
                        'opacity': '1'
                    }, c.imgBgsAnimationDuration);
                    i.filter('.selected').children('span').css({
                        'width': (parseInt(c.containerWidth) - parseInt(c.imgWidth)),
                        'display': 'none'
                    }).end().end().filter(this.hash).children('span').animate({
                        'width': c.tabsAnimateWidth
                    }, 0)
                }
                f.find('.selected').removeClass('selected');
                f.find(this.hash).each(function () {
                    $(this).addClass('selected')
                })
            })
        }
    }
    if (!document.defaultView || !document.defaultView.getComputedStyle) {
        var C = jQuery.curCSS;
        jQuery.curCSS = function (a, b, c) {
            if (b === 'background-position') {
                b = 'backgroundPosition'
            }
            if (b !== 'backgroundPosition' || !a.currentStyle || a.currentStyle[b]) {
                return C.apply(this, arguments)
            }
            var d = a.style;
            if (!c && d && d[b]) {
                return d[b]
            }
            return C(a, 'backgroundPositionX', c) + ' ' + C(a, 'backgroundPositionY', c)
        }
    }
    var D = $.fn.animate;
    $.fn.animate = function (a) {
        if ('background-position' in a) {
            a.backgroundPosition = a['background-position'];
            delete a['background-position']
        }
        if ('backgroundPosition' in a) {
            a.backgroundPosition = '(' + a.backgroundPosition
        }
        return D.apply(this, arguments)
    };

    function toArray(a) {
        a = a.replace(/left|top/g, '0px');
        a = a.replace(/right|bottom/g, '100%');
        a = a.replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2");
        var b = a.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
        return [parseFloat(b[1], 10), b[2], parseFloat(b[3], 10), b[4]]
    }
    $.fx.step.backgroundPosition = function (a) {
        if (!a.bgPosReady) {
            var b = $.curCSS(a.elem, 'backgroundPosition');
            if (!b) {
                b = '0px 0px'
            }
            b = toArray(b);
            a.start = [b[0], b[2]];
            var c = toArray(a.options.curAnim.backgroundPosition);
            a.end = [c[0], c[2]];
            a.unit = [c[1], c[3]];
            a.bgPosReady = true
        }
        var d = [];
        d[0] = ((a.end[0] - a.start[0]) * a.pos) + a.start[0] + a.unit[0];
        d[1] = ((a.end[1] - a.start[1]) * a.pos) + a.start[1] + a.unit[1];
        a.elem.style.backgroundPosition = d[0] + ' ' + d[1]
    }
})(jQuery);
var SiteFeatureAutoPlayInterval = [];

function siteFeatureAutoPlayer(a) {
    var b = $('.SF-' + a).find('#' + $.fn.siteFeature.defaults.tabIdPrefix + 'Container').children();
    if ((b.length - 1) == b.index(b.filter('.selected'))) {
        b.filter(':first').click()
    } else {
        b.filter('.selected').next().click()
    }
}
