function changeImg(id1, img1, id2, img2) {
  document.getElementById(id1).src = 'uploads/media/' + img1;
  if (id2 != '')
      document.getElementById(id2).src = 'uploads/media/' + img2;
}

function array_key_exists ( key, search ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
    // *     example 1: array_key_exists('kevin', {'kevin': 'van Zonneveld'});
    // *     returns 1: true
 
    // input sanitation
    if( !search || (search.constructor !== Array && search.constructor !== Object) ){
        return false;
    }
 
    return key in search;
}

var posArray = new Array();
var pos = 0;
var posStart = 0;
var posBack = 0;

$(document).ready(function() {
    $("a.scroll").each(function (i) {
        var id = $(this).attr("rel");
        if (i == 0) {
            posStart = $("#" + id).width() + 75;
        }
        if (id.substring(0,1) == 'c') {
            pos += $("#" + id).width() + 75;
            posArray[id] = pos;
        }
        if (id.substring(0,1) == 'b') {
            posArray[id] = posBack;
            posBack = pos;
        }

    });

    
    $("a.scroll").click(function() {
        var posString = posArray[$(this).attr("rel")] + "px";
        if ($(this).attr("rel") == "c_0")
            posString = "0px";
        $("#content_wrapper").animate({ 
            scrollLeft: posString
        }, 400);
    });
    $("a.navi").click(function() {
        var id = $(this).attr("rel");
        if (array_key_exists($(this).attr("rel"), posArray)) {
            var posString = (posArray[$(this).attr("rel")] - ($("#" + id).width() + 75)) + "px";    
        }
        else {
            var posString = ($("#content_table").width() - ($("#" + id).width() + 75) + 375) + "px";            
        }
        $("#content_wrapper").animate({ 
            scrollLeft: posString
        }, 400);
    });
});
