/**
 * @author rlacson
 */

$(document).ready(function(){
 	
    Cufon.replace('h1, h2, #content h3, .title, .prod_title, .title2, #address, #details, .pagination');
 	
    $('.scroll').jScrollPane();

    $('.popup_enquiry_link').click(function(){
        $("#enquiry_product_name").html($(this).attr("rel"));
    }).colorbox({
        inline: true,
        href: '#popup_enquiry_form'
    });

    //        $('.popup_enquiry_link').colorbox({
    //            inline: true,
    //            href: '#popup_enquiry_form'
    //        });
	
    $("#cta_categories a").live("click", function(){
        $('#tooltip').css("display", "none");
        $('#pc_sub_categ').show();        
        $(this).parent("li").addClass("bold_font");
        $(this).parent("li").siblings().removeClass("bold_font");
        
        
        return load_cta_data($(this).attr("href"),"cta_categories","cta_subcategories","cta_products");
    });

    $("#cta_subcategories a").live("click", function(){
        $('#pc_products').show();
        $(this).parent("li").addClass("bold_font");
        $(this).parent("li").siblings().removeClass("bold_font");
        
        return load_cta_data($(this).attr("href"),"cta_subcategories","cta_products",null);
    });

    $("#banner_images").cycle();

});
function load_cta_data(ajax_url, parent, attr_id, dependent){
    $("#"+parent+" a").each(function(){
        $(this).attr("class","");
    });
    $(this).attr("class","selected");
    //ajax_url = $(trigger).attr("href");
    ajax_loader = "<div class=\"scroll-pane\" id=\""+attr_id+"_container\"><div id=\""+attr_id+"\" class=\"items\"><div class=\"preload\"><img src=\"/images/core/ajax-loader.gif\" alt=\"LOADING...\" /></div></div></div>"
    //controls = "<div class=\"scrollable_controls\" id=\""+attr_id+"_controls\"><a href=\"#\" onclick=\"return false;\" class=\"image_link up prev\">UP</a><a href=\"#\" onclick=\"return false;\" class=\"image_link down next\">DOWN</a></div>"
    select = "<div class=\"scroll-pane\" id=\""+dependent+"_container\"><div id=\""+dependent+"\" class=\"items\"><div class=\"select item\">Select a Sub Category</div></div></div>"
    if(dependent!=null){
        $("#"+dependent+"_container").fadeOut("fast", function(){
            $("#"+dependent+"_container").replaceWith(select);
            //$("#"+dependent+"_controls").html("");
            $("#"+dependent+"_container").fadeIn("fast")
        });
    }
    $("#"+attr_id+"_container").fadeOut("fast",function() {
        $("#"+attr_id+"_container").replaceWith(ajax_loader);
        //$("#"+attr_id+"_controls").html("");
        $("#"+attr_id+"_container").fadeIn("fast",function(){
            $.ajax({
                type : "GET",
                url : ajax_url,
                success : function(data, stat) {
                    $("#"+attr_id+"_container").fadeOut("fast",function() {
                        $("#"+attr_id+"_container").replaceWith(data);
                        //$("#"+attr_id+"_controls").replaceWith(controls);
                        //if($("#"+attr_id+" .item").length < 2){
                        //$("#"+attr_id+"_controls").css("display","none");
                        //}
                        $("#"+attr_id+"_container").fadeIn("fast",function(){
                            $("#"+attr_id+"_container").jScrollPane();
                        });
                    });
                }
            });
        });
    });

    return false;
}

