// firebug degradiation
if (!("console" in window) || !("firebug" in console)) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group"
                 , "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    window.console = {};
    for (var i = 0; i < names.length; ++i) window.console[names[i]] = function() { };
}

var popUpWin = 0;
function popUpWindow(URLStr, left, top, width, height) {
    if (popUpWin) {
        if (!popUpWin.closed) popUpWin.close();
    }
    popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '');
}
var _browseImgPath = 'common/images/browse_btn.gif';
$(document).ready(function() {
    var pageName = new String(window.location);

    $('#wrapper img[src$=.png]').fixpng();
    $('label.overlabel').overlabel();
    //$(".image-container").equalizeCols();
    $(".link-print").click(function() {
        popUpWindow(window.location + '&print=true', 0, 0, 850, 700);
    });

    $('table.list-items>tbody>tr>td>table>tbody>tr').each(function() {
        $(this).find('div.dream').equalizeCols();
    });


    var params = pageName.toLowerCase();
    if (params.indexOf('?') != -1 && params.indexOf('print')) {
        var url = params.substring(0, params.indexOf('?'));
        params = params.substring(params.indexOf('?') + 1);
        params = params.substring(params.indexOf('print'));
        params = params.split('&');
        if (params[0].indexOf('print=') != -1) {
            var values = params[0].split('=');
            if (values[1] == 'true') {
                /*
                var oLink = document.createElement('link');
                oLink.setAttribute('href','/common/css/print.css');
                oLink.setAttribute('rel','stylesheet');
                oLink.setAttribute('type','text/css');
                $('html head').append(oLink);*/
                $("#header, .table_border1, .options, .area-right, .col-title, .col-title *, .col-left, .col-right, .vote-options a, .cufon-canvas canvas ").css("display", "none");
                $("#body .body-top").css("height", 60);
                $("#body.content .body-content .col-gallery").css("margin-top", "-20px");
                var dream = $(".dream-description");
                dream.find("*").css({ "font-family": "Arial, Helvetica, sans-serif", "font-variant": "normal", "color": "#222" });
                dream.find(".cufon-alt").css({ "font-size": "13px", "font-weight": "bold", "display": "block" });
                dream.find("p").css({ "line-height": "16px", "font-variant": "normal" });
                $(".cufon-canvas canvas").remove();
                window.print();
            }
        }
    }

    $(".pagination").each(function() {
        $('#dlPaging span').each(function() {
            var _this = $(this);
            if (_this.find('>a').length == 0) {
                _this.css('display', 'none');
            }
        });
        $(this).show("fast");
    });

    /*$('input[type=file]').each(function(){
    var _this = $(this);
    var _textID = _this.attr('id') +'_textbox';
    var _buttonID = _this.attr('id') +'_button';
    var _html = '<div class="input-file"><input readonly="readonly" class="textfield w210" type="text" id="'+_textID+'" /><input id="'+_buttonID+'" type="image" src="'+_browseImgPath+'" value="Browse" /></div>';
    _this.after(_html);
    _this.css({'position':'absolute',opacity:0});
    _this.change(function(){
    var __textID = '#'+$(this).attr('id') +'_textbox';
    $(__textID).val( $(this).val() );
    });
    });*/
});


/* =jQuery Plugins*/
(function($) {
    /* = plug-in : overlabel */
    $.fn.overlabel = function(options) {
        var opts = $.extend({}, $.fn.overlabel.defaults, options);
        var selection = this.filter('label[for]').map(function() {
            var label = $(this);
            var id = label.attr('for');
            var field = $('#' + id);
            if (!field) return;
            var o = $.meta ? $.extend({}, opts, label.data()) : opts;
            label.addClass(o.label_class);
            var hide_label = function() { label.css(o.hide_css) };
            var show_label = function() { this.value || label.css(o.show_css) };
            $(field)
					.parent().addClass(o.wrapper_class).end()
					.focus(hide_label).blur(show_label).each(hide_label).each(show_label);
            return this;
        });
        return opts.filter ? selection : selection.end();
    };
    $.fn.overlabel.defaults = {
        label_class: 'overlabel-apply',
        wrapper_class: 'overlabel-wrapper',
        hide_css: { 'display': 'none' },
        show_css: { 'display': 'block' },
        filter: false
    };
    /* =plug-in : fix-png */
    $.fn.fixpng = function() {
        var hack = {
            isOldIE: $.browser.msie && $.browser.version < 7,
            filter: function(src) { return "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + src + "');"; }
        };
        return this.each(function() {
            if (hack.isOldIE) {
                var $$ = $(this);
                if ($$.attr('src')) {
                    var span = document.createElement('span');
                    $(span).attr({
                        id: $$.attr('id'), className: $$.attr('class')
                    });
                    $(span).addClass('img-png');
                    $(span).css({
                        display: 'inline-block', width: $$.width(), height: $$.height(), filter: hack.filter($$.attr('src')), float: $$.attr('align') == 'left' ? 'left' : ($$.attr('align') == 'right' ? 'right' : 'none')
                    });
                    this.outerHTML = span.outerHTML;
                }
            }
        });
    };
    $.fn.zIndexFix = function() {
        var zIndexNumber = 1000;

        $("").each(function() {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber -= (zIndexNumber <= 0) ? 0 : 10;
        });
    };
    /* =plug-in : equal-heights */
    $.fn.equalizeCols = function() {
        var height = 0,
			 reset = $.browser.msie ? "1%" : "auto";
        return this
			.css("height", reset)
			.each(function() {
			    height = Math.max(height, $(this).outerHeight(true));
			})
			.css("height", height)
			.each(function() {
			    var h = $(this).outerHeight(true);
			    if (h > height) {
			        $(this).css("height", height - (h - height));
			    };
			});
    };
})(jQuery);

function goForSearch() {

    var title = document.getElementById("fastxtkeywords").value;
    var name = document.getElementById("fastxtname").value;
    var city = document.getElementById("fastxtcity").value;
    //var state=document.getElementById("ddlstate").value;
    var state = document.getElementById("ddlstate").value //selectedIndex;
    var age = document.getElementById("ddlage").value; //selectedIndex



    var url = "/SearchGallery.aspx?editmode=yes&title=" + title + "&name=" + name + "&city=" + city + "&state=" + state + "&age=" + age;
    top.window.location.href = url;
}

/************************************************/
/*PHASE 2 VOTING */

function ActivatePhase2VoteConfirmationLightBox() {

    var browser = navigator.appName;
    var b_version = navigator.appVersion;
    var version = parseFloat(b_version);

    if (browser == "Netscape") {
        var loginObj = document.getElementById("bPhase2Vote");
        loginObj.click();

    }
    else {
        var toClick = document.getElementById('aPhase2Vote')
        toClick.click();

    }

}

