/*-----------------------------------------
* Provides surferpix.com with Web 2.0 functionality.
* v1.2
* By Joem Costes
* http://www.joemcostes.com
* ---------------------------------- */
//Clientcide.setAssetLocation("/global/assets/");
//stand alone class:
//var myModalizer = new Modalizer();

var rfunc = function(arg1, arg2, arg3) {
    var a; var b;
    if ($('header2_svrn') != null) { a = $('header2_svrn').value; }
    if ($('ctl00_header_svrn') != null) { a = $('ctl00_header_svrn').value; }
    if ($('header_retstr') != null) { b = $('header_retstr').value; }
    if ($('ctl00_header_retstr') != null) { b = $('ctl00_header_retstr').value; }
    var y = arg1; var x = arg2; var z = arg3;
    var url = a + '/buy.aspx?c=buy&id=' + x + '&num=' + y + '&type=' + z + '&returl=' + escape(b);
    window.top.location.replace(url);
}

//TODO:explore new notification behaviors and design
var favs = function(arg1, arg2, arg3) {
    var x = arg1; var y = arg2; var z = arg3;
    var url = '/ajax/favs.aspx?c=add&id=' + x + '&num=' + y;
    new Ajax(url, {
        method: 'get', onRequest: function() { LoadAlert(z) },
        update: $(z)
    }).request();
}

var divToggle2 = function(arg1, arg2) {
    var x = $(arg1); if (x.style.display == 'none') { x.style.display = 'block'; } else { x.style.display = 'none'; }
    var y = $(arg2);
}
var navShow = function(arg1) {
    var x = arg1;
    $(x).style.display = 'block';
    $(x + "Top").style.display = 'block';
    $(x + "Bottom").style.display = 'block';    
}
var navHide = function(arg1) {
    var x = arg1;
    $(x).style.display = 'none';
    $(x + "Top").style.display = 'none';
    $(x + "Bottom").style.display = 'none';
}
var navTN = function(arg1, arg2) {
    var y = arg1; var x = arg2;
    if (y == 'show') {
        $(x).style.display = 'block';
        $(x + "Top").style.display = 'block';
        $(x + "Bottom").style.display = 'block';
    }
    if (y == 'hide') {
        $(x).style.display = 'none';
        $(x + "Top").style.display = 'none';
        $(x + "Bottom").style.display = 'none';
    }
}
//use to show the hidden layer above each thumbnail
// string (show/hide), string layerId
var TN = function(arg1, arg2) {
    var y = arg1; var x = arg2;
    if (y == 'show') { $(x).style.display = 'block'; }
    if (y == 'hide') { $(x).style.display = 'none'; }
}
//onmouseover ajax call for image thumbnails
var menuoptions = function(arg1, arg2, arg3, arg4) {
    var a = arg1; //imageid
    var b = arg2; //albumid
    var y = arg3; //id of the span i.e. (n_n)
    var o = arg4; //ListPrefixTag
    var urlstr = '/ajax/options.aspx';
    var options = 'c=options&id=' + b + '&num=' + a + '&m=' + y + '&o=' + o;
    if ($(y).innerHTML == '') 
    {
        var myRequest = new Request.HTML({
            method: 'get',
            url: urlstr,
            evalScripts: true,
            evalResponse: true,
            onRequest: function() { doSpinner('req', y); },
            onFailure: function() { doSpinner('fail', y); },
            update: $(y)
            //onSuccess: function() { lighboxAlert('good', y); } 
        });
        myRequest.send(options);
    }    
}

//ajax add item to order function
var mdis = function(arg1, arg2, arg3, arg4) {
    var a = arg1; //imageid
    var b = arg2; //albumid
    var c = arg3; //option
    var y = arg4; //id of the image to close    
    var urlstr = '/ajax/order.aspx';
    var options = 'c=buy&id=' + b + '&num=' + a + '&type=' + c;
    var myRequest = new Request({
        method: 'get',
        url: urlstr,
        onRequest: function() { doAlert('req', y); },
        onFailure: function() { doAlert('fail', y); },
        update: $(y),
        onSuccess: function() { lighboxAlert('good', y); }
    });
    myRequest.send(options);

    //sticky win for order response
    //    var myStickyWin = new StickyWin.Ajax({
    //        url: urlstr + "?" + options,
    //        wrapWithUi: true,
    //        caption: 'Orders > ' + a,
    //        closeOnEsc: true,
    //        destroyOnClose: true,
    //        onDisplay: function() {
    //            myModalizer.modalShow();
    //            myModalizer.setModalOptions({ hideOnClick: false, updateOnResize: true });
    //        },
    //        onClose: function() {
    //            myModalizer.modalHide();
    //            doAlert('highlight', y);
    //        }
    //    }).update(); 
    //    
}

var lighboxAlert = function(arg1, arg2) {
    var x = arg1;
    var y = arg2;
    if (x == 'good') {
        $(y).innerHTML = "<span class=\'smallfont\'><a href=\'/lightbox.aspx\'><img src=\'/images/icons/accept.png\' class=\'navarrow\'> view order</a></span>";
        $(y).setStyle('background', '#fffea1');
        
        //multiBox('lightbox', { descClassName: 'mbi', useOverlay: true, ajax: true });
    }
}

//load options from the thumbnail
var lol = function(arg1, arg2, arg3) {
    var a = arg1; //imageid
    var b = arg2; //albumid
    var y = arg3; //div to update
    var urlstr = '/ajax/favs.aspx';
    var options = 'c=fav&album=' + b + '&num=' + a;
    var myRequest = new Request.HTML({ 
        method: 'get', 
        url: urlstr, 
        onRequest: function() { doAlert('req', y); }, 
        onFailure: function() { doAlert('fail', y); }, 
        update: $(y)
        //onSuccess: function() { doAlert('good', y); } 
        });
    myRequest.send(options);

//    var myStickyWin = new StickyWin.Ajax({
//        url: urlstr + "?" + options,
//        wrapWithUi: true,
//        caption: 'Add to Favorites',
//        closeOnEsc: true,
//        destroyOnClose: true,
//        onDisplay: function() {
//            myModalizer.modalShow();
//            myModalizer.setModalOptions({ hideOnClick: false, updateOnResize: true });
//        },
//        onClose: function() {
//            myModalizer.modalHide();
//            doAlert('highlight', y);
//        }
//    }).update(); 
 }


//tides answer to ajax
var xtides = function(arg1, arg2) {
    var urlstr = arg1; //url
    var y = arg2; //div id
    var myRequest = new Request({
        method: 'get',
        url: urlstr,
        onRequest: function() { doAlert('req', y); },
        onFailure: function() { doAlert('fail', y); },
        update: $(y),
        onSuccess: function() { doAlert('good', y); }
    });
    myRequest.send();
}

//standard ajax notification
var doAlert = function(arg1, arg2) {
    var x = arg1;
    var y = arg2;
    if (x == 'req') { $(y).innerHTML = "<span class=\'smallfont\'><img src=\'/images/spinner.gif\' class=\'navarrow\'> loading</span>"; }
    if (x == 'fail') { $(y).innerHTML = "<span class=\'smallfont\'><img src=\'/images/exclamation.png\' class=\'navarrow\'> failed</span>"; }
    if (x == 'good') {
        $(y).innerHTML = "<span class=\'smallfont\'><img src=\'/images/icons/accept.png\' class=\'navarrow\'> success</span>";
        $(y).setStyle('background', '#fffea1');
    }
}

//Ajax Request for html content
var AjaxContent = function(arg1, arg2) {
    var urlstr = arg1; //url
    var y = arg2; //div
    var myRequest = new Request({
        method: 'get',
        url: urlstr,
        onRequest: function() { doAlert('req', y); },
        onFailure: function() { doAlert('fail', y); },
        update: $(y),
        onSuccess: function() { doAlert('good', y); }
    });
    myRequest.send();
}

//standard ajax notification
var doSpinner = function(arg1, arg2) {
    var x = arg1;
    var y = arg2;
    if (x == 'req') { $(y).innerHTML = "<img src=\'/images/spinner.gif\' class=\'navarrow\'>"; }
    if (x == 'fail') { $(y).innerHTML = "<img src=\'/images/exclamation.png\' class=\'navarrow\'>"; }
    if (x == 'good') {
        $(y).innerHTML = "<img src=\'/images/icons/accept.png\' class=\'navarrow\'>";        
    }
}
var box = {};
window.addEvent('domready', function() {
    var Tips1 = new Tips($$('.toolTipElement'), {
        timeOut: 700,
        maxTitleChars: 50, /*I like my captions a little long*/
        maxOpacity: .8 /*let's leave a little transparancy in there */
    });
    var Tips2 = new Tips($$('.toolTipElement'), {
        timeOut: 700,
        maxTitleChars: 50, /*I like my captions a little long*/
        maxOpacity: .8 /*let's leave a little transparancy in there */
    });
});

var ShowHideMenu = function(arg1, arg2) {
    var y = arg1;
    var x = arg2;
    if (y == 'show') {
        $(x).style.display = 'block';
    }
    if (y == 'hide') {
        $(x).style.display = 'none';
    }
}
var spinnerSH = function(arg1, arg2) {
    var x = arg1;
    var y = arg2;
    if (x == "hide")
    { $(y).style.display = 'none'; }
    if (x == "show")
    { $(y).style.display = 'block'; }
}
function getContent(arg1, arg2) {
    var x = arg1;
    var z = 'type=' + x;
    var url = '/ajax/photos.aspx?' + z;
    new Ajax(url, {
        method: 'get',
        onRequest: function() { spinnerSH('show', 'divLoading') },
        onFailure: function() { spinnerSH('show', 'divFailed') },
        onComplete: function() { spinnerSH('hide', 'divLoading') },
        update: $(arg2)
    }).request();
    //show
    divSH(arg2);
}

function getTag(arg1) {
    var x = arg1;
    var z = '?id=' + x;
    var y; if (x > 0) { y = '/ajax/tags.aspx' + z; } else { y = '/ajax/tags.aspx'; }
    var url = y;
    new Ajax(url, {
        method: 'get',
        onRequest: function() { spinnerSH('show', 'divLoading2') },
        onFailure: function() { spinnerSH('show', 'divLFail2') },
        onComplete: function() { spinnerSH('hide', 'divLoading2') },
        update: $('divTags')
    }).request();
    //show
    divSH2('divTags');
}       
// end public facing script //

