$(function () {
    $('a').each(
        function () {
            var href = $(this).attr('href');
            if ((href != null) && (href.indexOf('mailto') >= 0)) {
                $(this).bind(
                    'mouseover',
                    function () {
                        $(this).css("color", "red");
                    }
                );
                $(this).bind(
                    'mouseout',
                    function () {
                        $(this).css("color", "black");
                    }
                );

            }
        }
    );


    $("form.jqtransform").jqTransform();

    $('#menu > li').each(function () {
        $(this).find('li:first').addClass("primer");
    });


    $('#infoDestacatHeaderContainer').bind('click', function () {
        document.location.href = $(this).attr('urldestino');
    });


    $('#menu > li').hover(
			function () {
			    if ($.browser.msie) {
			        $(this).find("ul").show();
			    } else {
			        $(this).find("ul").fadeIn(100);
			    }
			},
			function () {
			    if ($.browser.msie) {
			        $(this).find("ul").hide();
			    } else {
			        $(this).find("ul").fadeOut(300);
			    }
			}
		);

    /*
    shortcut.add("Ctrl+Alt+Shift+E",
    function () {
    startEditOnline();
    },
    {
    'type': 'keydown',
    'propagate': true,
    'target': document
    }
    );
    */
	$("a.mmfitxallibret").fancybox({

		'height': 800,
		'width': 800,
		'type': 'iframe',
		'swf': {
			'allowfullscreen': 'true'
		}
	});


    $("#buscar").autocomplete($("#buscar").attr('url'), {
        width: 320,
        max: 4,
        highlight: false,
        scroll: true,
        scrollHeight: 300,
        dataType: "json",
        parse: function (data) {
            return $.map(data, function (row) {
                return {
                    data: row,
                    value: row.html,
                    result: row.text
                }
            });
        },
        formatItem: function (data, i, n, value) {
            return data.html;
        }
    });

    $('#buscar').keypress(function (e) {
        if (e.which == 13) {
            $('form#formCercar').submit();
        }
    });

    $('.exhaurit').bind(
        'click',
        function () {
            exhaurit();
        }
    );


    $('.proximamente').bind(
        'click',
        function () {
            proximamente();
        }
    );

    $(".llibre_digital").fancybox({
        'height': 750,
        'width': 1050,
        'type': 'swf',
        'autoScale': false,
        'swf': {
            'allowfullscreen': true,
            'wmode': 'transparent',
            'scale': 'exactfit'
        },
        'onStart': function () {
            $('iframe').hide();
        },
        'onComplete': function () {
            $('#fancybox-outer').addClass('llibret_digital');
            $('#fancybox-content').addClass('llibret_digital');
        },
        'onClosed': function () {
            $('iframe').show();
        }
    });

    $(".planol_sala1").fancybox({
        'height': 750,
        'width': 1050,
        'type': 'image',
        'autoScale': false
    });
    //trackPageLoadTime();
});

function obreLlibre(url) {
   $.fancybox({
        'href': url,
        'height': 750,
        'width': 1050,
        'type': 'iframe',
        'autoScale': false,
        'onStart': function () {
            $('iframe').hide();
        },
        'onComplete': function () {
            $('#fancybox-outer').addClass('llibret_digital');
            $('#fancybox-content').addClass('llibret_digital');
        },
        'onClosed': function () {
            $('iframe').show();
        }
    });
}

function goToAbonamentsAbonat(idAbonament, idHorari, numConcerts, idZona, nadults, njuniors, preuStr) {
    var url = "/" + idiomaWeb + "/abonaments/abonat?idAbonament=" + idAbonament;
    if (typeof idHorari != 'undefined') { url+= "&idHorari=" + idHorari }
    if (typeof numConcerts != 'undefined') { url+= "&numConcerts=" + numConcerts }
    if (typeof idZona != 'undefined') { url+= "&idZona=" + idZona }
    if (typeof nadults != 'undefined') { url+= "&nadults=" + nadults }
    if (typeof njuniors != 'undefined') { url+= "&njuniors=" + njuniors }
	if (typeof preuStr != 'undefined') { url+= "&preuStr=" + preuStr }	
    document.location.href = url;
}

function sendFormAjaxPost(idForm, callback) {
    var datos = $(idForm).serialize();
    var action = $(idForm).attr("action");
    $.post(action, datos, callback);
}

function showDisabled() {
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-message").dialog({
        modal: true        
    });
}


function exhaurit() {
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-exhaurit").dialog({
        modal: true
    });
}

function proximamente() {
    $("#dialog:ui-dialog").dialog("destroy");
    $("#dialog-proximamente").dialog({
        modal: true
    });
}


    


