﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />

var Duroc = {};

Duroc.DropDownLinks = {
    init: function() {
        jQuery('#link-selector').change(function() {
            var url = jQuery("option:selected", this).val();
            if (url != '') {
                var newwindow = window.open(url);
            }
        });
    }
};

Duroc.ExpandableTable = {
    table: null,
    init: function() {
        this.table = jQuery('.exp-table');
        this.setBehavior();
    },
    setBehavior: function() {
        jQuery(this.table).find('a.toggle').click(function(e) {
            e.preventDefault();
            var thisRow = jQuery(this).parent().parent();
            if (jQuery(thisRow).hasClass('open')) {
                jQuery(thisRow).removeClass('open');
                jQuery(thisRow).addClass('closed');
                jQuery(thisRow).next('tr.content').addClass('hidden');
            }
            else if (jQuery(thisRow).hasClass('closed')) {
                jQuery(thisRow).removeClass('closed');
                jQuery(thisRow).addClass('open');
                var newRow = jQuery(thisRow).next();
                jQuery(newRow).removeClass('hidden');
            }
            else {
                jQuery(thisRow).after('<tr class="content"><td colspan="2">loading</td></tr>');
                var item = this;
                jQuery.ajax({
                    type: "POST",
                    url: "/webservices/AjaxService.asmx/GetSupplier",
                    data: "{'pageid':'" + jQuery(this).attr('rel') + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    processData: false,
                    cache: false,
                    success: function(msg, status) {
                        // Replace the div's content with the page method's return.
                        //                    jQuery("").html(msg.d);
                        jQuery(thisRow).addClass('open');
                        var newCell = jQuery(thisRow).next().find('td');
                        jQuery(newCell).html(msg.d);
                    },
                    error: function(xhr, msg, e) {
                        alert(msg + ', ' + e); //Error Callback
                    }
                });
            }
        });
    }
};

jQuery(document).ready(function() {
    Duroc.DropDownLinks.init();
    Duroc.ExpandableTable.init();
    $("#header .duroc-link").append("<em></em>");

    jQuery('.duroc-link').hoverIntent({
        sensitivity: 1,
        interval: 0,
        timeout: 500,
        over: function() {
            jQuery('.duroc-link em').addClass('open'); jQuery('.duroc-link em').animate({ top: "5" }, "fast");
            var hoverText = jQuery(this).find('.stamp').attr("title");
            jQuery(".duroc-link em").text(hoverText);
        },
        out: function() { jQuery('.duroc-link em').animate({ top: "-60" }, "fast", null, function() { jQuery('.duroc-link em').removeClass('open'); }); jQuery('.duroc-link em').removeClass('expanded'); }
    });

    // Tabs
    jQuery('#tabs').tabs();
    jQuery("a.fancy-video").each(function() {
        var rel = $(this).attr('rel');
        $(this).fancybox({
            content: '<object width="425" height="355"><param name="movie" value="' + rel + '"></param>' +
                    '<param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param>' +
                    '<embed src="' + rel + '" type="application/x-shockwave-flash" allowscriptaccess="always" width="425" height="355" allowfullscreen="true"></embed>' +
                    '</object>'
        });
    });

    jQuery("a.fancy").fancybox({
        'titleShow': false,
        'transitionIn': 'elastic',
        'transitionOut': 'elastic'
    });
});