$(document).ready(function () {

    //QueryLoader.init();

    $("#header").load("content/header.html", initButtons);
    $("#footer").load("content/footer.html", initFooter);
    initSlideShow();
    contactenos();
    showCycle();


    //    if ($("#wrapper").hasClass("historia")) {
    //        $("#oneThirdContainer").load("content/left.html", initSlideShow);
    //        $("#twoThirdsContainer").load("content/historia.html", showCycle);
    //        $("#footer #activeBreadcrum a").html("Historia");
    //    }
    //    
    //    if ($("#wrapper").hasClass("contactenos")) {
    //        $("#oneThirdContainer").load("content/left.html", initSlideShow);
    //        $("#twoThirdsContainer").load("content/contactenos.html", contactenos);
    //        
    //    }
    //    
    //    if ($("#wrapper").hasClass("servicios")) {
    //        $("#oneThirdContainer").load("content/left.html", initSlideShow);
    //        $("#twoThirdsContainer").load("content/servicios.html", contactenos);
    //    }
    //	
    //	if ($("#wrapper").hasClass("productos")) {
    //        $("#oneThirdContainer").load("content/left-home.html", initSlideShow);
    //        $("#twoThirdsContainer").load("content/productos.html");
    //    }
    //    
    //    if ($("#wrapper_chat").hasClass("incluir")) {
    //    
    //        $('.fg-button').hover(function(){
    //            $(this).removeClass('ui-state-default').addClass('ui-state-focus');
    //        }, function(){
    //            $(this).removeClass('ui-state-focus').addClass('ui-state-default');
    //        });
    //        
    //        var nombre = $.readCookie('apodo');
    //		
    //        if (nombre && nombre != "") {
    //            $('.welcome').html("Bienvenido " + $.readCookie('apodo'));
    //        }
    //        else {
    //            $('#dialog_login').dialog('destroy');
    //            $("#dialog_login").dialog({
    //                bgiframe: true,
    //                width: 400,
    //                modal: true,
    //                resizable: false,
    //                closeOnEscape: false
    //            });
    //            $('.ui-dialog-titlebar-close').hide();
    //        }
    //        
    //        $('#login').submit(function(e){
    //            e.preventdefault;
    //            
    //            $.setCookie('apodo', $('#name').val(), {
    //                duration: 1, // In days
    //                path: '',
    //                domain: '',
    //                secure: false
    //            });
    //			$.setCookie('nuevo', "si", {
    //                duration: 1, // In days
    //                path: '',
    //                domain: '',
    //                secure: false
    //            });
    //            $('#apodo').val($('#name').val());
    //            $('#incluir_form').submit();
    //            $("#dialog_login").dialog("close");
    //        });
    //        
    //        $('#exit').bind("click", function(e){
    //            e.preventdefault;
    //            var exit = confirm("Esta seguro que desea finalizar la sesion?");
    //            if (exit == true) {
    //				document.location = $this.attr('href');
    //            }
    //            return false;
    //			
    //        });
    //        
    //    }
    //    if ($("#wrapper").hasClass("chat")) {
    //        $("#oneThirdContainer").load("content/left.html", initSlideShow);
    //        $("#slideshow").slideshow({
    //            pauseSeconds: 4,
    //            height: 174,
    //            width: 190,
    //            caption: false
    //        });
    //    }
    //    
    //    if ($("#wrapper").hasClass("home")) {
    //        $("#oneThirdContainer").load("content/left-home.html", initSlideShow);
    //        $("#twoThirdsContainer").load("content/home.html", contactenos);
    //    }

});

function showCycle(){
    $('.cycle').cycle({
        fx: 'fade',
        pager: '#nav',
        delay: -1000
    });
    $('#nav').addClass("fg-button ui-widget ui-state-default ui-corner-all");
    $('#nav a').addClass("ui-state-default");
    
}

function showDialog_jonathan(){
    $('#dialog_jonathan').dialog('destroy');
    $("#dialog_jonathan").dialog({
        bgiframe: true,
        height: 330,
        width: 500,
        modal: true,
        resizable: false,
        closeOnEscape: true
    });
}

function showDialog_creatica(){
    $('#dialog_creatica').dialog('destroy');
    $("#dialog_creatica").dialog({
        bgiframe: true,
        height: 330,
        width: 500,
        modal: true,
        resizable: false,
        closeOnEscape: true
    });
}

function initSlideShow(){

    $("#slideshow").slideshow({
        pauseSeconds: 4,
        height: 174,
        width: 190,
        caption: false
    });
	$("#slideshowGulf").slideshow({
        pauseSeconds: 4,
        height: 174,
        width: 190,
        caption: false
    });
    $("#slideshowproducts").slideshow({
        pauseSeconds: 4,
        height: 174,
        width: 180,
        caption: false
    });
}

function contactenos(){

    $('.fg-button').hover(function(){
        $(this).removeClass('ui-state-default').addClass('ui-state-focus');
    }, function(){
        $(this).removeClass('ui-state-focus').addClass('ui-state-default');
    });
    
    initTabs();
    initAccordion();
    initSlideShow()
}

function initTabs(){

    $("#tabs").tabs({
        fx: {
            opacity: 'toggle',
            duration: 'fast'
        }
    });
    $("#tabs").bind('tabsselect', function(event, ui){
        document.location = '#' + (ui.index + 1);
    });
    if (document.location.hash != '') {
        //get the index
        indexToLoad = document.location.hash.substr(1, document.location.hash.length);
        $("#tabs").tabs('select', indexToLoad - 1);
    }
    
}

function initAccordion(){
    $("#accordion").accordion({
        header: "h2",
        autoHeight: false
    });
}

function initButtons(){

    // BUTTONS
    $('.fg-button').hover(function(){
        $(this).removeClass('ui-state-default').addClass('ui-state-focus');
    }, function(){
        $(this).removeClass('ui-state-focus').addClass('ui-state-default');
    });
    
    // MENUS    	
    $('#remaq').menu({
        content: $('#remaq').next().html(), // grab content from this page
        showSpeed: 400,
        flyOut: true
    });
    $('#productos').menu({
        content: $('#productos').next().html(), // grab content from this page
        showSpeed: 400,
        flyOut: true
    });
	$('#online').menu({
        content: $('#online').next().html(), // grab content from this page
        showSpeed: 400,
        flyOut: true
    });

}

function initFooter(){

    $('a#target_jonathan').click(function(e){
        e.preventDefault();
        showDialog_jonathan();
    });
    
    $('a#target_creatica').click(function(e){
        e.preventDefault();
        showDialog_creatica();
    });
    
    $("#dialog_jonathan a img").hover(function(){
        $(this).effect("bounce", {
            times: 1
        }, 1000);
    });
    
    $("#dialog_creatica a div").hover(function(){
        $(this).effect("bounce", {
            times: 1,
            distance: 20
        }, 1000);
    });
    
    $("img").pngfix();
    
    
}

