﻿var $jq = jQuery.noConflict();

$jq(document).ready(function () {
    $jq('#start-search .search input[type=text]').focus(function () {
        clearField('#start-search .search input[type=text]');
    });
    $jq('#footer-search .search input[type=text]').focus(function () {
        clearField('#footer-search .search input[type=text]');
    });
    $jq('#header-bar .search input[type=text]').focus(function () {
        clearField('#header-bar .search input[type=text]');
    });
    dictionary();
    window.onload = function () {
        //placeMenuDrops(true,true)
        showNivoSlider();
    };
});

function clearField(theInput) {
    //alert($jq(theInput).attr("value")+'..'+$jq(theInput).val());
    if ($jq(theInput).attr("value") == $jq(theInput).val() && !$jq(theInput).hasClass('writing')) {
        $jq(theInput).val('');
        $jq(theInput).addClass('writing');
    }
}

function flash(id, src, w, h) {
    $jq(document).ready(function () {
        $jq('#' + id).flash(
			{ src: src,
			    width: w,
			    height: h
			},
			{ version: 10 }
		);
        $jq('#' + id).css('height', h);
    });
}

function dictionary() {
    $jq('#dictionaryselect').change(function () {
        var str = "";
        $jq("#dictionaryselect option:selected").each(function () {
            str = $jq('#' + $jq(this).val()).html();
        });
        if (str != null) {
            if (str.length > 0) {
                $jq("#dictionary-word").html(str);
            }
        }
    })
	.change();
}

function showDictionary(val) {
    $jq('#dictionaryselect').val(val);
    dictionary();
    $jq("#dictionary-word").animate({ color: '#fff' }, 'fast').animate({ color: '#666' });
    
}

function showNivoSlider() {
    //alert('showNivoSlider');
    if ($jq('#slider').length > 0) {
        if ($jq.browser.msie && $jq.browser.version < 9) {
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt').css('margin-right', '-5px');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-top').css('background', '#fffefe');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-top').css('border', '1px solid #8b949e');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-top').css('border-bottom', '0px');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-float, #site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-float p').css('background', '#fffefe');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-float').css('border', '1px solid #8b949e');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-float').css('border-top', '0px');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-float').css('border-bottom', '0px');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-bot').css('background', '#fffefe');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-bot').css('border', '1px solid #8b949e');
            $jq('#site.start #contentContainer #content-bg #start-content .hero-txt .hero-txt-bot').css('border-top', '0px');
        }
        $jq('#slider').nivoSlider({
            effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
            //slices: 15, // For slice animations
            //boxCols: 8, // For box animations
            //boxRows: 4, // For box animations
            animSpeed: 1000, // Slide transition speed
            pauseTime: 4000, // How long each slide will show
            //startSlide: 0, // Set starting Slide (0 index)
            directionNav: false, // Next & Prev navigation
            //directionNavHide: false, // Only show on hover
            controlNav: true, // 1,2,3... navigation
            //controlNavThumbs: false, // Use thumbnails for Control Nav
            //controlNavThumbsFromRel: false, // Use image rel for thumbs
            //controlNavThumbsSearch: '.jpg', // Replace this with...
            //controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
            keyboardNav: true, // Use left & right arrows
            pauseOnHover: true, // Stop animation while hovering
            //manualAdvance: false, // Force manual transitions
            captionOpacity: 1, // Universal caption opacity
            //prevText: 'Prev', // Prev directionNav text
            //nextText: 'Next', // Next directionNav text
            beforeChange: function () { }, // Triggers before a slide transition
            afterChange: function () { }, // Triggers after a slide transition
            slideshowEnd: function () { }, // Triggers after all slides have been shown
            lastSlide: function () { }, // Triggers when last slide is shown
            afterLoad: function () { } // Triggers when slider has loaded
        });
    }
}

function interactiveBg(showWidth, hideWidth, height) {
    //alert(showWidth+'---'+hideWidth);
    if ($jq('#interactive-bg').length > 0) {
        hideMargin = hideWidth - showWidth;
        $jq('#interactive-bg #interactive-bg-content').css('marginLeft', hideMargin);
        $jq('#interactive-bg, #interactive-bg #interactive-bg-content').css('height', height);
        $jq('#interactive-bg').hover(
			function () {
			    //$jq('#interactive-bg').css('width','500px');
			    //$jq('#interactive-bg #interactive-bg-content').css('marginLeft','0');
			    $jq('#interactive-bg').animate({
			        "width": showWidth
			    }, 300, function () {
			        // Animation complete.
			    });
			    $jq('#interactive-bg #interactive-bg-content').animate({
			        "marginLeft": 0
			    }, 300, function () {
			        // Animation complete.
			        //$jq('#interactive-bg-txt').css('display','block');
			        if ($jq.browser.msie && $jq.browser.version < 9) {
			            $jq('#interactive-bg-txt').fadeIn(0);
			        } else {
			            $jq('#interactive-bg-txt').fadeIn(100);
			        }
			    });
			},
			function () {
			    //$jq('#interactive-bg').css('width','150px');
			    //$jq('#interactive-bg #interactive-bg-content').css('marginLeft','-350px');
			    if ($jq('#interactive-bg').width() == showWidth) {
			        $jq('#interactive-bg').animate({
			            "width": hideWidth
			        }, 200, function () {
			            // Animation complete.
			        });
			        $jq('#interactive-bg #interactive-bg-content').animate({
			            "marginLeft": hideMargin
			        }, 200, function () {
			            // Animation complete.
			            //$jq('#interactive-bg-txt').css('display','none');
			            if ($jq.browser.msie && $jq.browser.version < 9) {
			                $jq('#interactive-bg-txt').fadeOut(0);
			            } else {
			                $jq('#interactive-bg-txt').fadeOut(100);
			            }
			        });
			    }
			}
		);
    }
}
