﻿var showArrows = false;

$(document).ready(function () {
    //HERO IMAGE SWAPPING
    $.fn.cycle.transitions.fade = function ($cont, $slides, opts) {
        var $el = $($slides[0]);
        var w = $el.width();
        var h = $el.height();
        opts.cssBefore = { top: 0, left: 15, width: w, height: h, zIndex: 1, opacity: 0 };
        opts.animIn = { top: 0, left: 0, width: w, height: h, opacity: 1 };
        opts.animOut = { opacity: 0 };
        opts.cssAfter = { zIndex: 0 };
    };

    $('#carousel').cycle({
        fx: 'fade',
        speed: 500,
        next: '#next',
        prev: '#prev',
        pause: 1,
	cleartype:  true,
     	cleartypeNoBg:  true,
        timeout: 9000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });

    $('#carouselNav').hide();
    $('#carouselHolder').hover(function () {
        showArrows = true;
	$('#carouselNav').stop(true, true).fadeIn(300);
    }, function () {
    	showArrows = false;
	setTimeout(hideCarouselNav(),500);
    });
    
    function hideCarouselNav() {
    	if (showArrows == false) {
    		$('#carouselNav').stop(true, true).fadeOut(300);
	}
    }
    
    $('#carouselNav').hover(function () {
    	showArrows = true;	
    });


    $('#carousel img').each(function () {
        $(this).css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src = '" + $(this).attr('src') + "')" });
    });




    /* Our Partners */
    //GET INITIAL WIDTH
    $('.partnerTicker li').each(function (intIndex) {
        actualwidth += parseInt($(this).width()) + parseInt($(this).css('paddingLeft')) + parseInt($(this).css('paddingRight'));
    });

    $('.partnerTicker').width(actualwidth)

    //INITIATE SECOND MARQUEE
    $('.partnerTicker').wrap('<div id="partnerHolder" style="position:relative;width:' + marqueewidth + ';height:' + marqueeheight + ';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">');
    $('.partnerTicker').clone().appendTo('#partnerHolder');


    //WRAP MARQUEE
    $('.partnerTicker:first').wrap("<div id='iemarquee' style='position:absolute;left:0px;top:0px;width:100%;'>");
    $('.partnerTicker:last').wrap("<div id='iemarquee2' style='position:absolute;left:0px;top:0px;width:100%;z-index:100;background:white;'>");

    populate();

});


/*
Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS, visit http://www.dynamicdrive.com
Modified by jscheuer1 for continuous content. Credit MUST stay intact for use
*/


var marqueewidth = "522px"    //Specify the marquee's width (in pixels)
var marqueeheight = "175px"   //Specify the marquee's height
var marqueespeed = 1          //Specify the marquee's marquee speed (larger is faster 1-10)
var initPause = 1000          //Specify initial pause before scrolling in milliseconds
var full = 1                  //Specify start with Full(1)or Empty(0) Marquee
var pauseit = 1               //Pause marquee onMousever (0=no. 1=yes)?
var iebreak = '<p></p>'


var copyspeed = marqueespeed
var pausespeed = (pauseit == 0) ? copyspeed : 0
var iedom = document.all || document.getElementById
var actualwidth = 0
var cross_marquee, cross_marquee2, ns_marquee


function populate() {
    if (iedom) {
        var lb = document.getElementById && !document.all ? '' : iebreak
        cross_marquee = document.getElementById ? document.getElementById("iemarquee") : document.all.iemarquee
        cross_marquee2 = document.getElementById ? document.getElementById("iemarquee2") : document.all.iemarquee2
        cross_marquee.style.left = (full == 1) ? '8px' : parseInt(marqueewidth) + 8 + "px"
        //cross_marquee2.innerHTML = cross_marquee.innerHTML = marqueecontent + lb
        //actualwidth = document.getElementById("partnerTicker").offsetWidth; //cross_marquee.offsetWidth
        cross_marquee2.style.left = (parseInt(cross_marquee.style.left) + actualwidth + 8) + "px" //indicates following #1
    }
    else if (document.layers) {
        ns_marquee = document.ns_marquee.document.ns_marquee2
        ns_marquee.top = parseInt(marqueeheight) + 8
        ns_marquee.document.write(marqueecontent)
        ns_marquee.document.close()
        actualheight = ns_marquee.document.height
    }
    setTimeout('lefttime=setInterval("scrollmarquee()",20)', initPause)
}

function scrollmarquee() {

    if (iedom) {
        if (parseInt(cross_marquee.style.left) < (actualwidth * (-1) + 8))
            cross_marquee.style.left = (parseInt(cross_marquee2.style.left) + actualwidth + 8) + "px"
        if (parseInt(cross_marquee2.style.left) < (actualwidth * (-1) + 8))
            cross_marquee2.style.left = (parseInt(cross_marquee.style.left) + actualwidth + 8) + "px"
        cross_marquee2.style.left = parseInt(cross_marquee2.style.left) - copyspeed + "px"
        cross_marquee.style.left = parseInt(cross_marquee.style.left) - copyspeed + "px"
    }

    else if (document.layers) {

        if (ns_marquee.top > (actualheight * (-1) + 8))
            ns_marquee.top -= copyspeed
        else
            ns_marquee.top = parseInt(marqueeheight) + 8
    }
}
