﻿var heroPos = {y:0};
var _tween;
var _pageName = "home";
var _imageStartX = -80;
var _imageStartY = 0;
var _imageEndY = -240;
var _text1Start = 190;
var _text2Start = 340;
var _fixFuzzyText = false;


function removeFilter(el)
{
    /*
        Fixes the "Blurry" text issue in IE7
        Due to ClearType and DxImageTransform not playing nicely together!
        See: http://mattberseth.com/blog/2007/12/ie7_cleartype_dximagetransform.html
    */
    //alert(typeof el.style.removeAttribute);
    if (el.style.filter && el.style.removeAttribute)
        el.style.removeAttribute('filter');
}


function startHero()
{
	_tween = new Ekina.UI.Effects.Tween(heroPos, "y", _imageStartY, _imageEndY, 2, Ekina.UI.Effects.Tween.Regular.InOut);
	_tween.start();
	_tween.onTweenStep = function(){$("hero-image-" + _pageName).style.backgroundPosition = _imageStartX + "px " + heroPos.y + "px";}
	_tween.onTweenFinished = startFadingText;
}

function startFadingText()
{
	setTimeout(fadeFirstText, 500);
	setTimeout(fadeSecondText, 1500);
}

function fadeFirstText()
{
	var aTween = Ekina.UI.Effects.Tween.alpha($("hero-text1-" + _pageName), 100, {duration:2, func:Ekina.UI.Effects.Tween.Regular.Out});
	var mTween = new Ekina.UI.Effects.Tween($("hero-text1-" + _pageName).style, "paddingLeft", _text1Start-10, _text1Start, 1, Ekina.UI.Effects.Tween.Regular.Out, "px");
	aTween.start();
	mTween.start();
	if (_fixFuzzyText)
	    aTween.onTweenFinished = function() { removeFilter($("hero-text1-" + _pageName)); }
}

function fadeSecondText()
{
	var aTween = Ekina.UI.Effects.Tween.alpha($("hero-text2-" + _pageName), 100, {duration:2, func:Ekina.UI.Effects.Tween.Regular.Out});
	var mTween = new Ekina.UI.Effects.Tween($("hero-text2-" + _pageName).style, "paddingLeft", _text2Start+10, _text2Start, 1, Ekina.UI.Effects.Tween.Regular.Out, "px");
	aTween.start();
	mTween.start();
	if (_fixFuzzyText)
	    aTween.onTweenFinished = function() { removeFilter($("hero-text2-" + _pageName)); }
}

function initHero(page, imageX, imageY, imageEndY, text1Start, text2Start, fixFuzzyText)
{
//    window.onload = function()
//    {
//	    if(Ekina.Browser.ie && Ekina.Browser.ie < 7)
//		    return;
//	    setTimeout(startHero, 1000)
//    };
//	    
//    Ekina.Events.register(window, "ondomready", function(){

//	    _pageName = page;
//	    _imageStartX = imageX;
//	    _imageStartY = imageY;
//	    _imageEndY = imageEndY;
//	    _text1Start = text1Start;
//	    _text2Start = text2Start;
//	    if (fixFuzzyText)
//	        _fixFuzzyText = true;


//	    if(Ekina.Browser.ie && Ekina.Browser.ie < 7)
//	    {}
//	    else {		
//		    $("hero-image-" + _pageName).style.backgroundPosition = _imageStartX + "px " + _imageStartY + "px";
//        }

//	    if(!$("hero-text1-" + _pageName) || !$("hero-text2-" + _pageName) || !$("hero-image-" + _pageName))
//		    alert("You need all the hero divs on the page");
//    	
//	    //Ekina.Events.register(window, "ondomready", function(){
//		    if(Ekina.Browser.ie)
//		    {
//			    $("hero-text1-" + _pageName).style.filter += "Alpha(opacity=0)";
//			    $("hero-text2-" + _pageName).style.filter += "Alpha(opacity=0)";
//		    }
//		    else
//		    {
//			    $("hero-text1-" + _pageName).style.opacity = 0;
//			    $("hero-text2-" + _pageName).style.opacity = 0;
//		    }
//		    $("hero-text1-" + _pageName).style.paddingLeft = _text1Start + "px";
//		    $("hero-text2-" + _pageName).style.paddingLeft = _text2Start + "px";
//	    //});
//    });
}




