﻿var basepath;

var pbQueue = new Array();
var argsQueue = new Array();

function load() {
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (!prm.get_isInAsyncPostBack())    
    {
        prm.add_initializeRequest(InitializeRequestHandler);  
        prm.add_endRequest(EndRequestHandler);     
    }
}

function InitializeRequestHandler(sender, args) {
    //code here
}

function EndRequestHandler() {
    /* CLEAR INPUT*/
    init_Behaviour();
    
    /*INIT EVENTS SCROLL*/
    init_Events();
	
	/* IMAGES + LINKS HOVER */
	init_Hover();
}

function init_Events() {
    (function($) {
        $('#events-control').html('');
    
        $(document).ready(function() {  
			if ($('#events-scroll').width()>0)
            $('#events-scroll').cycle({
                fx: 'fade',
                speed: 2000,
                timeout: 1,
                cleartype: 1,
                pager: '#events-control'
            });

            $('#events-control a').html('');
        });
    })(jQuery);
}

function init_Behaviour() {
    (function($) {
        /* CLEAR INPUT*/
        var tempform = '';
        $('input:text').focus(function() { if ($(this).val() == $(this).attr('title')) { tempform = $(this).val(); $(this).val(''); } });
        $('input:text').blur(function() { if ($(this).val() == '') { $(this).val(tempform); } });
    })(jQuery);    
}

function init_Hover() {
    (function($) {
       /* IMAGES + LINKS HOVER */
        $('img.hover').hover(
			function()
			{ this.src = this.src.replace("-off", "-on"); },
			function()
			{ this.src = this.src.replace("-on", "-off"); }
		);
        $('a.hover').hover(
			function()
			{ $('img', this).attr('src', $('img', this).attr('src').replace("-off", "-on")); },
			function()
			{ $('img', this).attr('src', $('img', this).attr('src').replace("-on", "-off")); }
		);

    })(jQuery);  
}

function doAfter(){


}		
	
(function($) {

    $(document).ready(function() {

        /* CLEAR INPUT*/
        init_Behaviour();

        /*INIT LOGO SLIDESHOW*/
		if ($('.slideshow').width()>0)		
        $('.slideshow').cycle({
            fx: 'fade',
            speed: 2000,
            timeout: 2000
        });

        /*INIT PROMOTII SLIDESHOW*/
		if ($('#promo-slideshow').width()>0)
        $('#promo-slideshow').cycle({
            fx: 'fade',
            speed: 2500,
            timeout: 2000,
            next: '#promo-prev',
            prev: '#promo-next'
        });

		/*INIT SLIDER SCROLL*/
		if ($('#content-show').width()>0)
		$('#content-show').cycle({
			fx:     'scrollHorz', 
			speed:  2000,
			timeout:0,
			cleartype:  1,
			after:   doAfter,
			easeIn:  'easeOutExpo', 
			easeOut: 'easeOutExpo', 
			next:   '#slider-next', 
			prev:   '#slider-prev'
		});
	
        /*STORES MAP*/
		if ($('a.map').width()>0)
        $("a.map").fancybox({
            'zoomSpeedIn': 600,
            'zoomSpeedOut': 600,
            'overlayShow': false,
            'easingIn': 'easeOutBack',
            'easingOut': 'easeInBack'
        });
		
		$("a#overlayf").fancybox({'overlayOpacity':0.6,'overlayColor':'#1D8503' }).trigger('click');


        /*INIT EVENTS SCROLL*/
        init_Events();


        /* BUTTONS */
        $('.button').bind('mouseover', function() { $(this).addClass('on') });
        $('.button').bind('mouseout', function() { $(this).removeClass('on') });
		
		 /* IMAGES + LINKS HOVER */
		init_Hover();
		
        /* PROMOS FANCYBOX */
		if ($('.promos a').width()>0)
        $(".promos a").fancybox({
            'zoomSpeedIn': 600,
            'zoomSpeedOut': 600,
            'overlayShow': false,
            'easingIn': 'easeOutBack',
            'easingOut': 'easeInBack'
        });

        /* MAP FANCYBOX */
		if ($('.interact li a').width()>0)
        $(".interact li a").eq(3).fancybox({
            'zoomSpeedIn': 600,
            'zoomSpeedOut': 600,
            'overlayShow': false,
            'easingIn': 'easeOutBack',
            'easingOut': 'easeInBack'
        });

        /*INIT TLSCMS*/
        $(".editable").each(function(i) {
            $j.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: cmsFullPath + "/GetGenericHtmC2PId",
                data: "{'url': '" + cmsLocation + "', 'ctrlIdx': '" + i + "'}",
                dataType: "json",
                success: function(msg) {
                    $j(".editable").eq(i).attr("id", msg.d);
                }
            });

        });

    });
})(jQuery);


function validateOnSubmit(container) {

    var bool = $j(container).validationEngine({ returnIsValid: true });
    if (bool) {
        return true;
    }
    else
        return false;
}
