// turn on this img if not already on
function rollOver(obj){obj.src = obj.src.replace(/(\.[a-z0-9]+)$/i,'_on$1');};

// turn off this img if not off
function rollOff(obj){obj.src = obj.src.replace(/_on(\.[a-z0-9]+)$/i,'$1');};

// behaviour rules
var rules = {
    '.email'  : function(element){
        element.onclick     = function (event) {
            var k = window.open(this.href, 'Inquiry', 'width=333,height=333,scrollbars=no');
            k.focus();
            return false;
        }
    },
    'a'   : function(element){
        element.onfocus = function(event) {
            this.blur();
        }
    },
    '#button' : function(element){
        element.onclick     = function () {
        
            var include   = encodeURI($('include').value);
            var exclude   = encodeURI($('exclude').value);
            var artist_id = encodeURI($('ArtistId').value);
            var medium    = encodeURI($('MediumId').options[$('MediumId').selectedIndex].text);
            
			include   = include   ? include : 0;
			exclude   = exclude   ? exclude : 0;
			artist_id = artist_id ? artist_id : 0;
			medium    = medium == 'Select%20Media'  ? 0 : medium;

            if(include != 0 || exclude != 0 || artist_id != 0 || medium != 0){
                window.location = '/cake/titles/results/' + include + '/' + exclude + '/' + artist_id + '/' + medium;
                return;
            }
            
            alert('Please enter at least one search term.');
            return false;
        }
    },
    '#search_form' : function(element){
        element.onsubmit     = function () {
        
            var include   = encodeURI($('include').value);
            var exclude   = encodeURI($('exclude').value);
            var artist_id = encodeURI($('ArtistId').value);
            var medium    = encodeURI($('MediumId').options[$('MediumId').selectedIndex].text);
            
			include   = include   ? include : 0;
			exclude   = exclude   ? exclude : 0;
			artist_id = artist_id ? artist_id : 0;
			medium    = medium == 'Select%20Media'  ? 0 : medium;

            if(include != 0 || exclude != 0 || artist_id != 0 || medium != 0){
                window.location = '/cake/titles/results/' + include + '/' + exclude + '/' + artist_id + '/' + medium;
                return false;
            }
            
            alert('Please enter at least one search term.');
            return false;
        }
    },
    '#value' : function(element){
        element.onkeydown    = function (event) {
            if(event.keyCode == 13){
                window.location = '/items/search/' + encodeURI(this.value);
                return;
            }
        }
    },
    '#print'  : function(element){
        element.onclick     = function (event) {
            var k = window.open(this.href, 'Print');
            k.focus();
            return false;
        }
    },
    '#page' : function(element){
        element.onchange    = function (event) {
            if(this.value){
                window.location = index_url + encodeURI(this.value);
                return;
            }
        }
    },
    '#page_form' : function(element){
        element.onsubmit    = function (event) {
            if($('page').value){
                window.location = index_url + encodeURI($('page').value);
                return false;
            }
        }
    }
};

Behaviour.register(rules);


Behaviour.addLoadEvent( function()
{
    /*
    var k = new Array();
    
    for(var i = 1; i <= 6; i++){
        k[i]     = new Image();
        k[i].src = $('i'+i).src.replace(/(\.[a-z0-9]+)$/i,'_on$1');
        $('debug').innerHTML = k[i].src;
    }
    */
});