﻿Sys.Application.add_init(OnApplicationInitHandler);

function OnApplicationInitHandler(sender, args) {    
    var homeButtonClicked = false;
	
	$(document).ready(function() {
		
		$.fn.cycle.defaults = { 
			delay:         -3000,
			random:			1,
			fx:            'fade',
			nowrap:        0,
			speed:         1000,
			startingSlide: 0,
			sync:          1,
			timeout:       3000,
			requeueOnImageNotLoaded: true,
			requeueTimeout: 250
		};
		
		
		// It's possible, with caching, that the images could
		//  be loaded *before* this code runs.  So:
		var is_image_loaded = function(img) {
			// IE
			if(!img.complete) {
				return false;
			}
			// Others
			if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
				return false;
			}
			return true;
		}
		
		var first_slide = $('#homeVisual img:first');
		if(is_image_loaded(first_slide.get(0))) {
			doCycle();
		} else {
			first_slide.load(function(e) {
				doCycle();
			});
		}

		function doCycle() {
			$('#homeVisual img').css({
				opacity: 0
			});
			setTimeout(function() {
				$('#homeVisual').cycle();
			
				$('#homeVisual img').css({
					opacity: 0
				});
			}, 3000);
		}
		
		if (!(Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7)) {
       
        $('#homemenu a')
            .css({ backgroundPosition: "0px -54px" })
            .mouseover(function() {
                if (!homeButtonClicked) {
                    $(this).stop().animate({ backgroundPosition: "(0px 0px)" }, { duration: 250, easing: "easeOutExpo" })
                }
            })
            .mouseout(function() {
                if (!homeButtonClicked) {
                    $(this).stop().animate({ backgroundPosition: "(0px -54px)" }, { duration: 250, easing: "easeOutExpo", complete: function() {
                        $(this).css({ backgroundPosition: "0px -54px" })
                    }
                    })
                }
            })
			
    	}
		
		$('#homemenu li#internet').click(function() {
				$('#topmenu li#internet').trigger('click');
		});
	})

}
