/*-----------------------------------------
* Provides surferpix.com with 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) {
    var a = arg1; //imageid
    var b = arg2; //albumid
    var y = arg2 + "_" + arg1; //id of the span i.e. (n_n)
    //var o = arg4; //ListPrefixTag
    // + '&m=' + y +'&o=' + o
    var urlstr = '/ajax/options.aspx';
    var options = 'id=' + b + '&num=' + a;
    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);
    }    
}

var artistinfo = function(arg1, arg2, arg3) {
    var y = arg1; //id of the span i.e. (albumId_imageId)
    var a = arg2; //imageId
    var o = arg3; //ownerid
    var urlstr = '/ajax/options.aspx';
    var options = 'c=tn&num=' + a + '&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);
    }
}
var artistavatar = function(arg1) {
    var o = arg1; //ownerid
    var urlstr = '/ajax/about.aspx';
    var options = 'c=avatar&o=' + o;
    var myRequest = new Request.HTML({
        method: 'get',
        url: urlstr,
        //evalScripts: true,
        //evalResponse: true,
        onRequest: function() { Notifyer('req'); },
        onFailure: function() { Notifyer('fail'); },
        update: $('overlayContent')
        //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.HTML({
        method: 'get',
        url: urlstr,
        onRequest: function() { Notifyer('req'); },
        onFailure: function() { Notifyer('fail'); },
        update: $('overlayContent')        
    });
    myRequest.send(options);
}
/* Basic Header Layer Container */
var ShowHeaderLayer = function(arg1, arg2, arg3) {
    var maxHeight = arg1;
    var speedFactor = arg2;
    var urlstr = arg3;
    $('AlbumsDisplayArea').style.display = 'block';
    $('forecastDisplayArea').style.display = 'none';
    $('AlbumTransitionArea').style.display = 'none';    
    
    //make div visible
    var mLayer = 'magicarea'; $(mLayer).style.display = 'block';
    var zContainer = 'AlbumsDisplayArea';

    if ($(mLayer).style.display == 'none') { $(mLayer).style.display = 'block'; }
    //change the height of the area
    $(mLayer).style.height = maxHeight;
    $(zContainer).style.height = maxHeight;
    var Yheight = $(mLayer).style.height;

    //Due to inheritance, all the [Fx][] options are available.
    var mylayer = new Fx.Slide(mLayer, {
        mode: 'vertical',
        onComplete: function() {
            if (urlstr != null) {
                var myRequest = new Request.HTML({
                    method: 'get',
                    evalScripts: false,
                    url: urlstr,
                    onRequest: function() { doSpinner('req', zContainer); },
                    onFailure: function() { doSpinner('fail', zContainer); },
                    update: $(zContainer)
                });
            }
        },
        duration: speedFactor,
        transition: Fx.Transitions.Pow.easeOut
    });

    //toggle and slideIn
    mylayer.toggle().chain(mylayer.slideIn);
    //morph
    var myEffects = new Fx.Morph(zContainer, { duration: speedFactor, transition: Fx.Transitions.Sine.easeOut });
    myEffects.start({ 'height': [Yheight, maxHeight] });
    //allow behavior to resize
    //$(zContainer).makeResizable({ modifiers: { x: false, y: 'height' }, limit: { y: [Yheight, maxHeight] }});
    //morph
    morphThisLayer(maxHeight, speedFactor, mLayer);
}
/* End Basic Header Layer Container */


/* Album layer for Ajax using MooTools lib 1.2.1*/
//arg1 = type | sorting
//arg2 = height | maxarea display
//arg3 = page | page index
var ShowAlbums = function(arg1, arg2, arg3) {
    //variables and defaults
    var type = arg1;
    var mHeight = arg2;
    var pageIndex = arg3;
    if (type == null) { type = 'newest'; }
    if ((mHeight == null) || (mHeight == '')) { mHeight = 300; }
    if (pageIndex == null) { pageIndex = 0; }
    //make div visible
    var x = 'magicarea'; $(x).style.display = 'block';
    if ($(x).style.display == 'none') { $(x).style.display = 'block'; }
    //change the height of the area
    $(x).style.height = mHeight +'px';
    var y = 50;
    
    //hide other containers
    $('AlbumTransitionArea').style.display = 'block';
    $('AlbumsDisplayArea').style.display = 'none';
    $('forecastDisplayArea').style.display = 'none';
    //Due to inheritance, all the [Fx][] options are available.
    var myalbums = new Fx.Slide('magicarea', { mode: 'vertical', duration: 1500, transition: Fx.Transitions.Pow.easeOut });
    //morph
    var myEffects = new Fx.Morph('AlbumTransitionArea', { duration: 750, transition: Fx.Transitions.Pow.easeOut });        
    //1st get the data
    var a = 'c=' + type + '&index=' + pageIndex; //type
    var j = 'AlbumNavContent'; //type
    var urlstr = '/ajax/albums.aspx';
    var options = a;
    var myRequest = new Request.HTML({
        method: 'get',
        evalScripts: false,
        url: urlstr,
        onRequest: function() {
            //doSpinner('req', j);
            myalbums.toggle().chain(myalbums.slideIn);        
            },
        onFailure: function() { doSpinner('fail', j); },
        update: $(j),
        onComplete: function() {
            //2nd resize layers
            myEffects.start({ 'height': [300, mHeight] });                       
        }
    });
    myRequest.send(options);
    //allow behavior to resize
    //$('spellcontent').makeResizable({modifiers: { x: false, y: 'height' },limit: { y: [20, 300] }});
}
/* End Album layer */


//Surf Forecast Layer Effect and Behavior
//task: show outer layer, resize laer, slide in the inner layer, resize the inner layer
var ShowForecast = function(arg1, arg2) {
    //pass region, get default or set default
    var region = arg1; if ((region == '') || (region == null)) { region = $('curregion').value; }
    //region still null set to default
    if ((region == '') || (region == null)) { region = 'hawaii', $('curregion').value = 'hawaii'; }
    $('AlbumTransitionArea').style.display = 'none';
    $('AlbumsDisplayArea').style.display = 'none';
    $('forecastDisplayArea').style.display = 'block';
    //change height
    var mHeight = arg2;
    if (arg1 == null) { mHeight = 600; }

    //alert(region);
    $('nanana').innerHTML = "";
    $('momomo').innerHTML = "";

    //make area visible if not visible
    var x = 'magicarea'; $(x).style.display = 'block';
    if ($(x).style.display == 'none') { $(x).style.display = 'block'; }

    //change the height of the area
    $(x).style.height = mHeight + 'px';

    //SlideIn the container, Due to inheritance, all the [Fx][] options are available.
    var mySlide = new Fx.Slide('magicarea', {
        mode: 'vertical',
        duration: 1500,
        transition: Fx.Transitions.Pow.easeOut,
        onComplete: function() {
            if (mySlide.open) {
                //xtides('/helpers/ww3.aspx?view=patc', 'spellcontent');
                var a = 'view=' + region; //type
                var y = 'nanana'; //type
                var urlstr = '/helpers/ww3.aspx';
                var options = a;
                var myRequest = new Request.HTML({
                    method: 'get',
                    evalScripts: true,
                    url: urlstr,
                    onRequest: function() { doSpinner('req', y); },
                    onFailure: function() { doSpinner('fail', y); },
                    update: $(y),
                    onComplete: function() {
                        defaultCast(region + "-default");
                    }
                });
                myRequest.send(options);
            } //end of if
        } //end if onComplete
    });

    //toggle and slideIn
    mySlide.toggle().chain(mySlide.slideIn);

    //morph
    var myEffects = new Fx.Morph('forecastDisplayArea', { duration: 1000, transition: Fx.Transitions.Sine.easeOut });
    myEffects.start({ 'height': [300, mHeight] });

    //allow behavior to resize
    //$('spellcontent').makeResizable({modifiers: { x: false, y: 'height' },limit: { y: [20, 600] }});
}
/* Surf Forecast Ajax calls */
//Update Surf Watch (slide out and slide in)
var updateCast = function(arg1, arg2) {
    //make area visible if not visible
    var x = 'magicarea'; $(x).style.display = 'block';
    if ($(x).style.display == 'none') { $(x).style.display = 'block'; }
    //
    var mHeight = arg2;
    if (arg1 == null) { mHeight = 600; }
    //change the height of the area
    $(x).style.height = mHeight + 'px';
    
    //SlideIn the container, Due to inheritance, all the [Fx][] options are available.
    var mySlide = new Fx.Slide('magicarea', { mode: 'vertical',duration: 1500, transition: Fx.Transitions.Pow.easeOut });
    //morph
    var myEffects = new Fx.Morph('forecastDisplayArea', { duration: 1000, transition: Fx.Transitions.Sine.easeOut });
    
    var a = 'view=' + arg1; //type
    var y = 'momomo'; //type
    var urlstr = '/helpers/ww3.aspx';
    var options = a;
    var myRequest = new Request.HTML({
        method: 'get',
        evalScripts: true,
        url: urlstr,
        onRequest: function() {
            //toggle and slideIn
            mySlide.toggle().chain(mySlide.slideIn);
            //doSpinner('req', y); 
            },
        onFailure: function() { doSpinner('fail', y); },
        update: $(y),
        onComplete: function() {
            myEffects.start({ 'height': [300, mHeight] }); 
            //init rss accordion display
            RssFeedAccordion();
        }
    });
    myRequest.send(options);
}

//Update Surf Watch (default no slide out and slide in)
var defaultCast = function(arg1) {
    //alert(arg1);
    var x = arg1; //type
    var y = 'momomo';
    var urlstr = '/helpers/ww3.aspx';
    var options = 'view=' + x;
    var myRequest = new Request.HTML({
        method: 'get',
        url: urlstr,
        evalScripts: false,
        onRequest: function() { doSpinner('req', y); },
        onFailure: function() { doSpinner('fail', y); },
        update: $(y)
    });
    myRequest.send(options);
}

//script for the surf forecast navigation. I know its a little bulky but I have very little time
//slated to be revamp for mootools 1.2.4 & clientside 2.2.0 (though i just wrote it)
var SurfwatchSlides = function(arg1) {
    var x = arg1;
    //alert(x);
    //$('btnregionalprev').style.display = "block";
    //$('btnregionalnext').style.display = "block";
    //var theTitle = document.getElementById('regionalTitle');    
    var action = $(x).value;
    //alert(action);    
    var mHeight = 425;
    var curregion = $('curregion').value;
    if ((curregion == '') && (curregion == null)) { $('curregion').value = "hawaii"; }
    switch (action) {
        case "hawaii":
            $('prevregion').value = "eastcoast";
            $('nextregion').value = "california";
            mHeight = 425;
             //$('regionalTitle').value = "Hawaiian Islands";
            //theTitle.nodeValue = "Hawaiian Islands";
            break;
        case "california":
            $('prevregion').value = "hawaii";
            $('nextregion').value = "eastcoast";
            mHeight = 600;
             //$('regionalTitle').value = "California (West Coast)";
            //theTitle.nodeValue = "California (West Coast)";
            break;
        case "eastcoast":
            $('prevregion').value = "california";
            $('nextregion').value = "hawaii";
            mHeight = 600;
            //$('regionalTitle').value = "East Coast";
            //theTitle.nodeValue = "East Coast";
            break;
        default:
            $('prevregion').value = "eastcoast";
            $('nextregion').value = "california";
            //$('regionalTitle').value = "Hawaiian Islands";
            //theTitle.nodeValue = "Hawaiian Islands";
            break;
    }
    //alert("nextregion: " + $('nextregion').value);
    //alert("prevregion: " + $('prevregion').value);
    //alert(document.getElementById('regionalTitle').lastChild.nodeValue);
    //alert(action);
    ShowForecast(action, mHeight);
}
var RssFeedAccordion = function() {
    //create our Accordion instance
    var myAccordion = new Accordion($('rssfeed'), '.toggler', '.element', {
        opacity: false,
        onActive: function(toggler, element) {
            toggler.setStyle('color', '#41464D');
        },
        onBackground: function(toggler, element) {
            toggler.setStyle('color', '#528CE0');
        }
    });
    
    //myAccordion.addSection(toggler, content, position);
}

/* Overlay Notification */
//onClick: closeOverlay()
var overlay = {}; window.addEvent('domready', function() { overlay = new Overlay({  }); });
//init slider 
window.addEvent('domready', function() {
     /* Resizable with Vertical Limit */
    var mySlide = new Fx.Slide('magicarea', { 
        mode: 'vertical',
        duration: 500,
        transition: Fx.Transitions.Pow.easeOut
    });
    mySlide.toggle();
 });

 //morph the layer that is passed
//arg1: max height, arg2: speed, arg3: name of the element
 var morphThisLayer = function(arg1, arg2, arg3) {
     var maxHeight = arg1;
     var speedFactor = arg2;
     var zContainer = arg3;
     var currentHeight = $(zContainer).style.height;
     
     var myEffects = new Fx.Morph(zContainer, { duration: speedFactor, transition: Fx.Transitions.Sine.easeOut });
     myEffects.start({ 'height': [currentHeight, maxHeight] });
 }  

var Notifyer = function(arg1) {
    var x = arg1;
    var gtop = ((window.getSize().y / 2) - 100 + getScrollTop());
    var gleft = ((window.getSize().x / 2) - 200);

    if (x == 'req') {
        $('overlaynotifyer').setStyle('display', 'block');
        $('overlaynotifyer').setStyle('top', gtop);
        $('overlaynotifyer').setStyle('left', gleft);
        $('overlayContent').innerHTML = "<div style=\"text-align:center; vertical-align:middle;\"><img src=\'/images/loading.gif\' class=\'navarrow\'><br/>Loading. Please Wait... </div>";
        overlay.show();

    }
    if (x == 'fail') {
        $('overlaynotifyer').setStyle('display', 'block');
        $('overlaynotifyer').setStyle('top', gtop);
        $('overlaynotifyer').setStyle('left', gleft);
        $('overlayContent').innerHTML = "<div style=\"text-align:center; vertical-align:middle;\"><img src=\'/images/warning.gif\' class=\'navarrow\'><br/>Opps! Something went wrong ... </div>";
        overlay.show();
    }
}
var closeOverlay = function() {
        $('overlayContent').innertHTML = null;
        $('overlaynotifyer').setStyle('display', 'none');
        overlay.hide();           
        }
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');        
    }
}

//load options for 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() { Notifyer('req'); },
        onFailure: function() { Notifyer('fail'); },
        update: $('overlayContent')
        //onSuccess: function() { doAlert('good', y); } 
        });
    myRequest.send(options);
   }
var knockit = function(arg1, arg2, arg3) {
       var a = arg1; //imageid
       var b = arg2; //albumid
       var y = arg3; //type thumb up/down
       var urlstr = '/ajax/favs.aspx';
       var options = 'c=thumbs&num=' + a + '&updown=' + y;
       var myRequest = new Request.HTML({
           method: 'get',
           url: urlstr,
           onRequest: function() { Notifyer('req'); },
           onFailure: function() { Notifyer('fail'); },
           update: $('overlayContent')
           //onSuccess: function() { doAlert('good', y); } 
       });
       myRequest.send(options);
   }


//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/loading_pie.gif\' class=\'navarrow\'> loading</span>"; }
    if (x == 'fail') { $(y).innerHTML = "<span class=\'smallfont\'><img src=\'/images/icons/error.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;
    try 
    {
    if (x == 'req') { $(y).innerHTML = "<img src=\'/images/icons/loading_pie.gif\' class=\'navarrow\'>"; }
    if (x == 'fail') { $(y).innerHTML = "<img src=\'/images/icons/error.png\' class=\'navarrow\'>"; }
    if (x == 'good') { $(y).innerHTML = "<img src=\'/images/icons/accept.png\' class=\'navarrow\'>"; }    
    }
    catch(e)
    {
        //return "error";
    }
}
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 //
