var newColor = ["framered.png","frameblack.png","framebrown.png","framelight.png","frameblue.png","framegreen.png","padauk.png","maple.gif","mahogany.gif"];
var newImage = ["wflower1.png","wflower0.png","wpaper0.png","wpaper1.png","flower2.gif","wdamask2.png","damaskblack.gif","damask1color.gif","mongolblack.gif","mongolblue.gif","mongolbrown.gif","mongolred.gif"];

function set_default(fields){
    var image_width = $('#postImg').outerWidth(true);
    var image_height = $('#postImg').outerHeight(true);
    var copyrightx = Math.round(image_width - $('#postImg').innerWidth())/2 + 40;
    var copyrighty = Math.round(image_height - $('#postImg').innerHeight())/2 + 55;
    var window_height = $(window).height();
    var window_width = $(window).width();
    var photo_y = Math.round( window_height/ 2 - (image_height+74) / 2 - 30);
        if (photo_y < 15) photo_y = 15;
    var photo_x = Math.round(window_width / 2 - image_width / 2);
        if (photo_x < 90) {photo_x = 120};
    if ( fields[11] == "0px") {
        $('.fframe').css('visibility','hidden'); 
        $('#postImgMatt').css('visibility','visible');
        $('#postImg').css('visibility','visible');  
        $('#frameContainer').css({'background':'none'});}
    $('#frameContainer').css({left: photo_x+"px", top: photo_y+"px", width: image_width+80+"px",
                            height: image_height+80+"px", visibility: "visible"});
    $('#copyright').css({left:"55px", bottom: "50px", visibility: "visible"});
    $('#exif_information').css({right: "55px", bottom:"50px", visibility: "visible"});
    $('#social_buttons').css({right: "135px", bottom:"50px", visibility: "visible"});
    $('#uigarjinlogo').css({'left': photo_x-65+"px", 'top':photo_y+40+"px"}).fadeIn('slow');
}

function postInit(fields){
    if (fields[3] != ""){$('#changeBack').css({ 'backgroundImage':"url(templates/mongoltolbo/images/" + newImage[fields[3]]+")"}) 
    } else { $('#changeBack').css({ 'backgroundImage':"url(templates/mongoltolbo/images/" + newImage[0]+")"})}
    $('#postImg').css({"margin":fields[5], "border":fields[6],"background-color":fields[1],"padding":fields[2]}); 
    $('#postImgMatt').css({"background":"url(templates/mongoltolbo/frames/trans/"+newColor[fields[4]]+")", "border":fields[7]})
    $('#frameContainer').css({'backgroundImage':"url(templates/mongoltolbo/frames/trans/"+newColor[fields[0]]+")"});
    if ( fields[9] != "" ) {$('#imageTitle').css({'left':fields[8],'bottom':fields[9],'color':fields[10]})}
}
function setFrameColor(i) {
    $('#frameContainer').css({'backgroundImage':"url(templates/mongoltolbo/frames/trans/"+newColor[i]+")"})
}
function setBg(i) {
    if (i!=""){ $('#changeBack').css({'backgroundImage':"url(templates/mongoltolbo/images/"+newImage[i]+")"}) }
        else {$('#changeBack').css({'backgroundImage':"url(templates/mongoltolbo/images/"+newImage[0]+")"})}
}
function set_change_wall(){
    $('#change_tgwall').click(function(event){$("#buttonframe").fadeOut('slow');
    $("#change_wall").fadeIn('slow')});
    $('#change_wall').mouseleave(function(event){$("#change_wall").fadeOut("slow")})
}
function set_frame_color(){
    $('#frame_tgcolor').click(function(event){
            $("#change_wall").fadeOut('slow');$("#buttonframe").fadeIn('slow')});
    $('#buttonframe').mouseleave(function(event){$("#buttonframe").fadeOut('slow')})
}

function thumbnailsTip(){
        $("a.thumbnails").cluetip({splitTitle: '|', clickThrough: true, width: '200px', truncate: 155,
        delayedClose: 5000, tracking: true,fx:{open:'fadeIn',openSpeed:'2500'},positionBy: 'mouse'})
}                   

function loadFrames(LoadPage, Audio) {
        framecode="<frameset rows='*,14px'>" + "<frame frameBorder='1' src='"+LoadPage+"'>"+
            "<frame frameBorder='1' src='" + Audio + "'>" + " </frameset>";
        page = window.open(""); page.document.open();   page.document.write(framecode); page.document.close()
}


function set_colorInit(){
    $('#tgcolorInit').click(function(event){
                    $("#colorInit").animate({right: '5px'},
                                        { duration: 1500,easing: 'easeOutBounce'})
                    });
    $('#colorInit').mouseleave(function(event){
                    $("#colorInit").animate({right: '-340px'},
                                       { duration: 1500,easing: 'easeOutBounce'})
                    })
}

function set_left_panel(){
    $('#h_toggle').toggle(
        function(){$("#left_panel").animate({left: '0px'},2000,'swing')
        },function() {$("#left_panel").animate({left: '-536px'},2000,'easeOutExpo')});
    $('#exif_information').click(function(event) {
            $("#left_panel").animate({left: '0px'},2000,'easeOutExpo')});
    $('#left_panel').mouseleave(function(event) {
        $("#left_panel").animate({left: '-536px'},2000,'easeOutBounce')})
}

function checkCookieBg(){
    newImage = getCookie('mongoltolbo');
    if (newImage != null && newImage != ""){
     document.getElementById('changeBack').style.backgroundImage = "url(templates/mongoltolbo/images/"+newImage+")";
    } else {
     document.getElementById('changeBack').style.backgroundImage = "url(template/mongoltolbo/images/bg.png)";
      setCookie('mongoltolbo',"bg.png",365);}}  
function getCookie(c_name){
    if (document.cookie.length > 0){
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1){
            c_start = c_start + c_name.length+1;
            c_end = document.cookie.indexOf(";",c_start);
            if (c_end == -1) c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}
function setCookie(c_name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays == null) ? "" : ";expires="+exdate.toGMTString());
}

 /*@example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @author Klaus Hartl/klaus.hartl@stilbuero.de */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) { value = ''; options.expires = -1; }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else { date = options.expires;}
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break;
                }
            }
        } return cookieValue;
    }
}
