﻿// JavaScript Document

$(document).ready(function() {
    var ie = false;
    var ie8 = false;
    var ie7 = false;
    var ie6 = false;

    var thisURL = 1;

    if ($.browser.version == '8.0' && $.browser.msie) {
        ie8 = true;
        ie = true;
    } else if ($.browser.version == '7.0' && $.browser.msie) {
        ie7 = true;
        ie = true;
    } else if ($.browser.version == '6.0' && $.browser.msie) {
        ie6 = true;
        ie = true;
    }

    // Set the ID of the search box
    srch = $('#ctl00_txtSearch', '#nav');

    // Set the default search box text
    defSrchTxt = srch.val();

    // Replace search text on focus
    srch.focus(function() {
        if ($(this).val() == defSrchTxt) {
            $(this).val('');
        }
    });

    srch.blur(function() {
        if ($(this).val() == '') {
            $(this).val(defSrchTxt);
        }
    });

    // Fix the height on products and looks lists
    var maxHeight = 0;
    var maxH2Height = 0;

    // Set the text for Expand and Minimize
    minText = $('div#minimize-text').html();
    expText = $('div#expand-text').html();

    // Set the height on the looks / products divs and headings to create a "table-like" layout
    $(window).load(
    function() {
        // Fix the divs
        $('#looks li, #products li').each(function() {
            hgt = $(this).height();

            if (maxHeight <= $(this).height()) {
                maxHeight = $(this).height();
                $('#looks li, #products li').each(function() {
                    if ($(this).height() < maxHeight) {
                        $(this).height(maxHeight);
                        if (ie8) {
                            $(this).css('border', '1px solid white');
                        }
                    }
                });
            }
        });
        // Fix the headings
        $('#looks li h2, #products li h2').each(function() {
            hgt = $(this).height();

            if (maxH2Height <= $(this).height()) {
                maxH2Height = $(this).height();
                $('#looks li h2, #products li h2').each(function() {
                    if ($(this).height() < maxH2Height) {
                        $(this).height(maxH2Height);
                        if (ie8) {
                            $(this).css('border', '1px solid white');
                        }
                    }
                });
            }
        });

        // Sort out the in-page pop ups (fix needed due to Sifr)
        if (ie6) {
            winHeight = $(window).height();
            winWidth = $(window).width();

            $('#share-friend-wrapper').css('display', 'none').css('width', winWidth + 'px').css('height', winHeight + 'px').css('overflow', 'auto').css('margin', '0');
            $('#permalink-wrapper').css('display', 'none').css('width', winWidth + 'px').css('height', winHeight + 'px').css('overflow', 'auto').css('margin', '0');
        } else {
            $('#share-friend-wrapper').css('display', 'none').css('position', 'fixed').css('width', '100%').css('height', '100%').css('overflow', 'auto').css('margin', '0');
            $('#permalink-wrapper').css('display', 'none').css('position', 'fixed').css('width', '100%').css('height', '100%').css('overflow', 'auto').css('margin', '0');
        }
    }
);


    /* 
    Karl Swedberg's js class technique
    via http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx
    */

    $('html').addClass('js');
    /* Variables */
    var expandedYet = 0;
    var resizedYet = 0;

    // IE6 BGFIX fix & remove bump class
    if (ie6) {
        $('#wrapper').prepend('<div style="height:' + $(window).height() + 'px; width: 1px; float: left;" id="ie6force">&nbsp;</div>');
        $('#bgfix').height($(window).height());
        $('.bump').removeClass('bump');
        $('.lhs').removeClass('lhs');
    }

    /* Cache selectors */
    var wrapper = $('#wrapper');
    var mailShareLink = $('a.email', 'dl.nav-social');
    var permLink = $('a.perma-link', 'dl.nav-social');

    // Scroll to the right place on page anchor links
    if (window.location.hash) {
        // Make sure it scrolls to the right place
        // This curently just worsk for Looks and Products .. it can be made to work for other parts of the site
        if ($('#looks li, #products li').length > 0) {
            $('#looks li, #products li').each(function(index) {
                $(this).prepend('<div id="l' + (index + 1) + '" style="position: absolute; height: 1px; width: 1px; margin-top: -150px;"></div>');
            });
        }
    }

    /* HTML additions / changes */
    $('#content-primary1 .title-box, #content-secondary2 .title-box, #content-secondary3 .title-box, #content-primary4 .title-box, #content-primary5 .title-box, #content-primary .title-box6').append('<img src="/assets/images/line-hide.jpg" class="hider1" border="0" /><img src="/assets/images/line-hide.jpg" class="hider2" border="0" />');

    $('#wrapper').prepend('<div id="additions"></div>');

    // Permalink
    /*
    var permAdd = '<div id="permalink-wrapper">    <div id="permalink-holder"><a href="#" id="close-permalink">X</a>        <h1 id="permalink-title" class="goth">Permalink</h1>            <fieldset>                <textarea name="permalink" id="permalink"></textarea>                <div class="pin">&nbsp;</div>                <a href="#" class="button" id="permalink-copy">Dela till blogg <span>&gt;</span></a>            </fieldset>    </div></div>';
    */

    $('.faq.loaded, .about-content.loaded').fadeIn('slow');

    // Add in the "reset" button 
    $('<dt id="reset"><a href="#">RESET</a></dt>').insertAfter('#in');

    // Add colspans into xform tables
    $('#contact-form, #competition-form').find('tr:last').find('td').addClass('button-holder');

    $('#contact-form, #competition-form').find('tr').find('td:last').filter(function() {
        return $('label', this).length < 1;
    }).remove();

    $('#contact-form, #competition-form').find('tr').find('td:only-child').attr('colspan', '2');

    /* Share with a friend */
    $('a#share_btn').live("click", function() {
        $('span#share-error').css('display', 'none');
        if ($('input#email1').val() != "" && $('input#email2').val() != "") {

            //validate email format
            var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (filter.test($("input#email1").val()) && filter.test($("input#email2").val())) {

                //create parameters
                var email1 = $('input#email1').val();
                var email2 = $('input#email2').val();
                var comments = $('textarea#add-comment').val();
                var url = window.location.href;

                //send a post to asp.net to send an email
                $.ajax({
                    type: "POST",
                    url: "/ShareWithFriend.aspx/SendMail",
                    contentType: "application/json; charset=utf-8",
                    data: "{'email1':'" + email1 + "' ,'email2':'" + email2 + "','comments':'" + comments + "','url':'" + url + "'}",
                    dataType: "json",
                    success: AjaxSucceeded,
                    error: AjaxFailed
                });
            }
            else {
                $('span#share-error').html("Felaktigt email format");
                $('span#share-error').css('display', 'block');
            }
        }
        else {
            $('span#share-error').html("Båda email adresserna måste vara ifyllda");
            $('span#share-error').css('display', 'block');
        }
    });

    function AjaxSucceeded(result) {
        $('div#share-friend-wrapper').css('display', 'none');
    }
    function AjaxFailed(result) {
        //todo:display error div?
    }

    // Set the minimum height on the main content div
    function setLines() {
        var browserHeight = $(window).height() - 133;
        if (ie6) {
            $('#content-primary1, #content-primary2, #content-secondary2, #content-primary3, #content-primary4, #content-primary5, #content-primary6').css('height', browserHeight + 20);
            $('#content-secondary3').css('height', browserHeight + 0);
        } else {
            $('#content-primary1, #content-primary2, #content-secondary2, #content-primary3, #content-primary4, #content-primary5, #content-primary6').css('min-height', browserHeight);
            $('#content-secondary3').css('min-height', browserHeight + 20);
        }
    }

    setLines();
    $(window).bind("resize", setLines);

    // Specific one for the map page
    var mapHeight = $('#wrapper').height() - 83;
    $('#content-secondary2').css('minHeight', mapHeight);

    /* Nav expander */
    /*
    Temporarily disabled
    $('#nav-main').find('a').live("click",function () {
    toGoTo = $(this).attr('href');
    currentLink = $(this);
    if (($(this).attr('class') != 'current-page' && $(this).parent().parent().attr('id') == 'nav-main')) {
    if ($('.current-page').length > 0) {
    $('.current-page').removeClass('current-page').parent().find('ul').fadeOut('fast', function () {
    currentLink.addClass('current-page').parent().find('ul').fadeIn('slow', function () {
    window.location.href = toGoTo;																			  
    });
    });
    }
		
		
    } else {
    window.location.href = toGoTo;
    }

	return false;
    });

*/

    /* Email form */
    var t = 0;
    var mailWrapper = $('#share-friend-wrapper, #close-friend', '#wrapper');
    var mailForm = $('#share-friend-holder', '#wrapper');

    var cp = 0;
    var permWrapper = $('#permalink-wrapper, #close-permalink', '#wrapper');
    var permForm = $('#permalink-holder', '#wrapper');



    function peekerBoo(flag) {
        if (flag == 1 && t == 0) {
            t = 1;
        }
        if (t == 0) {
            $('#share-friend-wrapper', '#wrapper').fadeIn('slow');
            t = 1;
        } else {
            $('#share-friend-wrapper', '#wrapper').fadeOut('slow');
            t = 0;
        }
    }

    function peekerBooPerm(flag) {
        if (flag == 1 && cp == 0) {
            cp = 1;
        }
        if (cp == 0) {
            $('#permalink').text(flag);
            $('#permalink-wrapper', '#wrapper').fadeIn('slow');
            cp = 1;
        } else {
            $('#permalink-wrapper', '#wrapper').fadeOut('slow');
            cp = 0;
        }
    }

    mailShareLink.live("click", function() {


        peekerBoo();

        return false;
    });

    mailWrapper.live("click", function() {


        peekerBoo(1);

        return false;
    });

    mailForm.live("click", function() {

        return false;
    });



    permLink.live("click", function() {
        thisLink = $(this).attr('href');
        peekerBooPerm(thisLink);
        return false;
    });

    permWrapper.live("click", function() {
        peekerBooPerm(1);
        return false;
    });

    permForm.live("click", function() {
        return false;
    });



    /* Note: You'll obviously need to do something Ajaxy to submit the form and return a thank you messsage */





    /* Acordians for FAQ and About pages */



    $('.faq-link').live("click", function() {
        r = 0;
        if ($(this).parent().find('.faq').css('display') != 'none') { r = 1; }
        $(this).parent().parent().find('.faq').css('display', 'none');
        $(this).parent().parent().find('.faq-link').removeClass('loaded');

        if (r == 0) {
            $(this).parent().find('.faq').fadeIn('slow');
            $(this).addClass('loaded');
        }
        return false;
    });

    $('.about-link').live("click", function() {
        r = 0;
        if ($(this).parent().find('.about-content').css('display') != 'none') { r = 1; }
        $(this).parent().parent().find('.about-content').css('display', 'none');
        $(this).parent().parent().find('.about-link').removeClass('loaded');

        if (r == 0) {
            $(this).parent().find('.about-content').fadeIn('slow');
            $(this).addClass('loaded');
        }
        return false;
    });



    /* Image Gallery */
    var prevLink = $('#prev a', '#nav-gallery');
    var nextLink = $('#next a', '#nav-gallery');

    // The highest image is s4.jpg
    var imgMax = $("[id$='_image_gallery_count']").html();
    var baseURL = $("[id$='_image_gallery_firstimage']").html();

    // Cache the images for the gallery
    if ($("[id$='_image_gallery_count']").length > 0 && $("[id$='_image_gallery_firstimage']").length > 0) {
        var s = 0;
        var m = 1;
        var galleryImgWidth = $('.rhs').css('width').split('px');
        galleryImgWidth = galleryImgWidth[0];
        imgMax = imgMax * 1;
        var galleryHolderWidth = (imgMax + 2) * galleryImgWidth;
        // var codeInsert = '<div id="image-cut" style="height: '+ 300+'px; width: '+galleryHolderWidth+'px; overflow: hidden;"><div id="gallery-holder" style="width: '+galleryHolderWidth+'px, margin-left: -'+galleryImgWidth+'px; float: left;">';
        var codeInsert = '<div id="image-cutter" style="width: ' + galleryHolderWidth + 'px; margin-left: -' + galleryImgWidth + 'px"><div id="gallery-holder" style="width: ' + galleryHolderWidth + 'px, margin-left: -' + galleryImgWidth + 'px; float: left;">';
        codeInsert += '<img src="' + baseURL + imgMax + '.jpg" class="gallery-img" style="width: ' + galleryImgWidth + 'px" />';
        for (s = imgMax; m <= s; m++) {
            codeInsert += '<img src="' + baseURL + m + '.jpg" class="gallery-img" style="width: ' + galleryImgWidth + 'px" />';
        }
        codeInsert += '<img src="' + baseURL + '1' + '.jpg" class="gallery-img" style="width: ' + galleryImgWidth + 'px" />';
        codeInsert += '</div></div>';
        $('#image-holder').html(codeInsert);
    }



    nextLink.live("click", function() {

        if (nextLink.attr('rel') != 'disable') {
            nextLink.attr('rel', 'disable');

            prevURL = targetURL = $('#prev a').attr('rel');
            nextURL = $('#next a').attr('rel');

            thisURL++;
            if (thisURL > imgMax) { thisURL = 1; }

            peekerBoo(1);

            // Fix the bottom collapsing issue
            // $('#image-holder').css('margin-bottom','12px');
            // $('.fullwide #image-holder').css('margin-bottom','11px');
            /* if (ie7 || ie6) {
            $('ul#nav-gallery').css('bottom','101px');
            } else {
            $('ul#nav-gallery').css('bottom','88px');
            };
            */


            // Slide the image to the LEFT
            var galleryImgWidth = $('.rhs').css('width').split('px');
            galleryImgWidth = galleryImgWidth[0];
            imgMax = imgMax * 1;
            var galleryHolderWidth = (imgMax + 2) * galleryImgWidth;

            $('#gallery-holder', '#image-gallery').animate(
			  {
			      marginLeft: '-=' + galleryImgWidth + 'px'
			  },
			  375,
			  function() {

			      j = $(this).css('margin-left').split('px');
			      j = j[0] * 1;


			      //	thisMarginLeft = (thisURL * (-1 * galleryImgWidth)) + Math.floor((thisURL / 2) * galleryImgWidth);

			      if (j < ((2 * galleryImgWidth) - galleryHolderWidth + 1)) {
			          $(this).css('margin-left', 0 + 'px');
			      }

			      nextLink.delay(375).attr('rel', 'enable');
			  });

            // Update the links
            // Let's start off by assuming all the links follow the format sX.jpg where X is an integer.

            // let's make both the previous and the next one LOWER
            /*
            prevURL--;
            nextURL--;
		
		if (nextURL < 1) {nextURL = imgMax};
            if (prevURL < 1) {prevURL = imgMax};
		
		//Update the RELs of the two links
            $('#prev a').attr('rel',prevURL) ;
            $('#next a').attr('rel',nextURL) ;
            */
        }
        return false;
    });

    prevLink.live("click", function() {
        if (prevLink.attr('rel') != 'disable') {
            prevLink.attr('rel', 'disable');

            prevURL = $('#prev a').attr('rel');
            nextURL = targetURL = $('#next a').attr('rel');

            thisURL--;
            if (thisURL < 1) { thisURL = imgMax; }

            peekerBoo(1);

            // Fix the bottom collapsing issue
            /* $('#image-holder').css('margin-bottom','12px');
            $('.fullwide #image-holder').css('margin-bottom','11px');
            if (ie7 || ie6) {
            $('ul#nav-gallery').css('bottom','101px');
            } else {
            $('ul#nav-gallery').css('bottom','88px');
            };
            */


            // Slide the image to the RIGHT
            var galleryImgWidth = $('.rhs').css('width').split('px');
            galleryImgWidth = galleryImgWidth[0];
            imgMax = imgMax * 1;
            var galleryHolderWidth = (imgMax + 2) * galleryImgWidth;

            j = $('#gallery-holder', '#image-gallery').css('margin-left').split('px');
            j = j[0] * 1;

            if ((j + 1) > 0) {
                $('#gallery-holder', '#image-gallery').css('margin-left', '-' + (galleryHolderWidth - (2 * galleryImgWidth)) + 'px');
            }

            $('#gallery-holder', '#image-gallery').animate(
			  {
			      marginLeft: '+=' + galleryImgWidth + 'px'
			  },
			  375, function() {
			      prevLink.delay(375).attr('rel', 'enable');
			  });

            /*
            prevURL++; 
            nextURL++;
		
		if (nextURL > imgMax) {nextURL = 1};
            if (prevURL > imgMax) {prevURL = 1};
		
		//Update the RELs of the two links
            $('#prev a').attr('rel',prevURL) ;
            $('#next a').attr('rel',nextURL) ;
            */
        }
        return false;
    });




    /* Magnify image */

    function zoomCentreImage() {

        currentZoom = 1;
        $('#zoom-container a').draggable('destroy');
        $('#zoom-container').removeClass('drag-cursor');

        var zCWidth = $('#zoom-container').width();
        var zCHeight = $('#zoom-container').height();
        var pIHeight = $('#product-image').width() + 2000;
        var pIWidth = $('#product-image').height() + 2000;


        var heightOffset = ((pIHeight - zCHeight) / 2) * 1;
        var widthOffset = ((pIWidth - zCWidth) / 2) * 1;

        newHeight = Math.round(zCWidth / originalRatio);

        $('#zoom-container').css('height', newHeight);
        $('#zoom-container img').css({ 'width': zCWidth, 'height': newHeight, 'margin-left': 0, 'margin-top': 0 });
        $('#zoom-container a').css('top', 0);
        $('#zoom-container a').css('left', 0);

        $('#product p a img, #product img.dont-hide').css({ 'top': 0,
            'left': 0
        });
    }

    var currentZoom = 1;
    var originalWidth = $('#product-image').width();
    var originalHeight = $('#product-image').height();
    var originalRatio = originalWidth / originalHeight;
    var zoomWidth;
    var zoomHeight;
    var zoomedYet = 0;

    // Product Image Zoom In
    $("#in").live("click", function() {
        zWidth = $('#zoom-container').width();
        zHeight = zWidth * (originalHeight / originalWidth);

        if (currentZoom < 4) {

            currentZoom++;

            zoomWidth = zWidth * currentZoom;
            zoomHeight = zHeight * currentZoom;

            topM = -zoomWidth / (10 / currentZoom);
            leftM = -zoomWidth / (10 / currentZoom);

            $('#zoom-container a').animate(
          {
              top: 0,
              left: 0
          },
          { duration: 350, easing: 'easeInOutCirc' }
        );

            if (ie6) {
                $('#product-image').animate(
			  {
			      width: zoomWidth,
			      height: zoomHeight,
			      marginLeft: leftM,
			      marginTop: 0
			  },
			  { duration: 350, easing: 'easeInOutCirc' }
			);
            } else {
                $('#product-image').animate(
			  {
			      width: zoomWidth,
			      height: zoomHeight,
			      marginLeft: leftM,
			      marginTop: topM
			  },
			  { duration: 350, easing: 'easeInOutCirc' }
			);
            }

            if (currentZoom > 1) {
                $('#zoom-container a').draggable();
                $('#zoom-container').addClass('drag-cursor');
            } else {
                $('#zoom-container a').css({ 'top': '0', 'left': '0' }).draggable('destroy');
                $('#zoom-container').removeClass('drag-cursor');
            }
            if (ie7) {
                if (currentZoom != 2) {
                    x = $('.drag-cursor a').css('left').split('px');
                    x = x[0] * 1;
                    x = Math.round((x / 4) + (64));
                } else if (zoomedYet == 0) {
                    x = 64;
                    zoomedYet = 1;
                } else {
                    x = -100;
                }
                $('.drag-cursor a').css('left', x + 'px');
            } else if (ie6) {
                if (currentZoom == 3) {
                    x = -350;
                } else if (currentZoom == 4) {
                    x = -600;
                } else if (zoomedYet == 0) {
                    x = -150;
                    zoomedYet = 1;
                } else {
                    x = -100;
                }
                $('.drag-cursor a').css('margin-left', x + 'px');
            }
        }

        return false;
    });

    // Product Image Zoom Out
    $("#out").live("click", function() {

        if (currentZoom == 1) {
            $('#product-image').attr('width', originalWidth);
            $('#product-image').attr('height', originalHeight);
            $('#zoom-container a').css({ 'top': '0', 'left': '0' }).draggable('destroy');
            $('#zoom-container').removeClass('drag-cursor');
        }
        else if (currentZoom > 0) {

            currentZoom--;

            zoomWidth = zWidth * currentZoom;
            zoomHeight = zHeight * currentZoom;

            topM = -zoomWidth / (10 / currentZoom);
            leftM = -zoomWidth / (10 / currentZoom);

            if (currentZoom == 1) {
                topM = 0;
                leftM = 0;
            }

            $('#zoom-container a').animate(
          {
              top: 0,
              left: 0
          },
          { duration: 350, easing: 'easeInOutCirc' }
        );

            if (ie6) {
                $('#product-image').animate(
			  {
			      width: zoomWidth,
			      height: zoomHeight,
			      marginLeft: leftM,
			      marginTop: 0
			  },
			  { duration: 350, easing: 'easeInOutCirc' }
			);
            } else {
                $('#product-image').animate(
			  {
			      width: zoomWidth,
			      height: zoomHeight,
			      marginLeft: leftM,
			      marginTop: topM
			  },
			  { duration: 350, easing: 'easeInOutCirc' }
			);
            }

            if (ie7) {
                if (currentZoom != 2) {
                    x = $('.drag-cursor a').css('left').split('px');
                    x = x[0] * 1;
                    x = Math.round((x / 4) + (64));
                } else {
                    x = -100;
                }

                $('.drag-cursor a').css('left', x + 'px');
            } else if (ie6) {
                if (currentZoom == 3) {
                    x = -350;
                } else if (currentZoom == 4) {
                    x = -600;
                } else if (currentZoom == 2) {
                    x = -150;
                } else {
                    x = 0;
                }
                $('.drag-cursor a').css('margin-left', x + 'px');
            }

        }
        return false;
    });

    // RESET the Zoom
    $("a", "#reset").live("click", function() {
        $('#product-image').css('width', originalWidth);
        $('#product-image').css('height', originalHeight);
        $('#zoom-container a').css({
            'top': '0',
            'left': '0'
        }).draggable('destroy').find('img').css({
            'margin-top': '0',
            'margin-left': '0'
        });
        $('#zoom-container').removeClass('drag-cursor');
        currentZoom = 1;
        return false;
    });

    // Product Image Gallery
    $('#product-gallery a').click(function() {
        oldImg = $('#product-image').attr('src');
        $('#product-image').attr('src', $(this).attr('href'));

        // Replace the thumbnail
        $(this).attr('href', oldImg);
        $(this).find('img').attr('src', oldImg);
        return false;
    });

    jQuery.fn.resizeWidthMaintainRatio = function(newWidth) {
        aspectRatio = $(this).height() / $(this).width();
        $(this).width(newWidth);
        $(this).height(newWidth * aspectRatio);
    };

    function resizeMe() {
        // Temp Disable for IE6
        if (ie6) { return false; }

        // If there's no expand button, we don't want it
        if ($(".expand").length == 0) { return false; }

        var lhs = $('#content-primary1');
        var rhs = $('#content-secondary1');

        if (lhs.length == 0) {
            rhs = $('#content-primary2');
            lhs = $('#content-secondary2');
        }

        if (lhs.length == 0) {
            rhs = $('#content-primary5');
            lhs = $('#content-secondary3');
        }

        // LHS is always the left, and RHS is always the right.

        var lhsW = lhs.width();
        var rhsW = rhs.width();
        var minW = 0;
        var maxW = 0;
        var startType;

        if (lhsW > rhsW) {
            minW = rhsW;
            maxW = lhsW;
            startType = 0;

        } else {
            minW = lhsW;
            maxW = rhsW;
            startType = 1;
        }

        // Our Original Column Sizes
        var bigColOriginal = maxW;
        var smallColOriginal = minW;
        var snapToPoint = 0;

        // Allow a manual override of the max / min width using the rel in the lhs div 
        isSetMaxMin = $('.lhs').attr('rel');

        if (isSetMaxMin > 0 && startType == 1) {
            maxW = isSetMaxMin;
        } else if (isSetMaxMin > 0 && startType == 1) {
            minW = isSetMaxMin;
        }

        if (startType == 1) {
            snapToPoint = lhsW * 1.25;
        } else {
            snapToPoint = lhsW * 0.75;
        }

        var rhsMarginBig = rhs.css("margin-left");

        // Default
        var rhsMarginSmall = "700px";
        if (rhs.attr("class").indexOf("px") != -1) {
            cs = rhs.attr("class").split(" ");
            rhsMarginSmall = cs[cs.length - 1];
        }

        // Is there a manual override on width?

        navMargin = 200;

        if (isSetMaxMin > 0) {
            q = isSetMaxMin.toString();
            q = q * 1;

            if (startType == 1) {
                rhsMarginSmall = rhsMarginSmall.substr(0, rhsMarginSmall.lastIndexOf('px'));
                rhsMarginSmall = rhsMarginSmall * 1;
                rhsMarginSmall = rhsMarginSmall - (q / 2);
                rhsMarginSmall = rhsMarginSmall + (q / 25);
                if (isSetMaxMin < 360) {
                    rhsMarginSmall = rhsMarginSmall - 13;
                }
                rhsMarginSmall = rhsMarginSmall + 'px';
            }
        }
        var startSize = lhs.width();



        $("img", lhs).each(function() {
            jQuery.data($(this).get(0), "originalWidth", $(this).width());
        });

        $("img", rhs).each(function() {
            jQuery.data($(this).get(0), "originalWidth", $(this).width());
        });

        // Do the magic, initialize resizable
        lhs.resizable({
            handles: 'e',
            minWidth: minW,
            maxWidth: maxW
        });


        // While we're dragging, executed every pixel moved
        lhs.bind('resize', function(event, ui) {
            resizedYet = 1;

            // Fix the bottom collapsing issue on the image gallery
            $('#image-holder').css('margin-bottom', '0');
            $('ul#nav-gallery').css('bottom', '100px');

            d = lhsW - $(this).width();
            rhs.width(rhsW + d);

            // Work out the margin-left
            var rhsML = rhs.css("margin-left").match(/\d+/gi);
            ss = (rhsML - d) + "px";

            if (ie7 || ie6) {
                ss = (rhsML) + "px";
            }
            rhs.css("margin-left", ss);

            updateContainedItems();

            resizeImageGallery();
        });

        lhs.bind('resizestart', function(event, ui) {
            startSize = lhs.width();

            // Fix the bottom collapsing issue on the image gallery
            $('#image-holder').css('margin-bottom', '0');
            $('ul#nav-gallery').css('bottom', '100px');

            $("img", lhs).each(function() {
                jQuery.data($(this).get(0), "originalWidth", $(this).width());
            });

            $("img", rhs).each(function() {
                jQuery.data($(this).get(0), "originalWidth", $(this).width());
            });
            return true;
        });

        // Store image sizes


        lhs.bind('resizestop', function(event, ui) {
            // Snap-to
            if (lhs.width() > snapToPoint) {
                toggleSize(true);
            } else {
                toggleSize(false);
            }

            // Fix the bottom collapsing issue
            $('#image-holder').css('margin-bottom', '0');
            $('ul#nav-gallery').css('bottom', '100px');

            // IN IE7 set the margin-left
            if (ie7 || ie6) {
                rhs.css("margin-left", "10px");
                $('#content-primary5.rhs').css("margin-left", "0");
            }
            // Calculate the min-height
            var lastElement = $("*:last", lhs).prev();

            zoomCentreImage();
        });


        /* The actual resizing */
        function toggleSize(lhsBig) {

            if (lhsBig === false) {
                lhs.width(smallColOriginal);

                if (isSetMaxMin > 0) {
                    rhs.width(bigColOriginal);
                }

                if (ie7 || ie6) {
                    // rhs.css("left", "auto");
                    rhs.width(bigColOriginal).css("margin-left", rhsMarginBig);
                }
                else if (ie == false) {
                    rhs.width(bigColOriginal).css("margin-left", rhsMarginBig);
                }

            } else {
                var y = 0;
                // This only works for set values
                if (isSetMaxMin > 0) {
                    if (isSetMaxMin == 400) {
                        y = 170;
                    } else {
                        y = 170;
                    }
                }

                rhs.width(smallColOriginal);
                lhs.width(bigColOriginal - y);

                if (ie7 || ie6) {
                    if ($('.prodsfix').length != 0) {
                        rhs.css({ "margin-left": "571px", "width": "354px" });
                    } else if ($('.looksfix').length != 0) {
                        rhs.css({ "margin-left": "526px", "width": "414px" });
                    } else {
                        rhs.css("margin-left", rhsMarginSmall);
                    }
                }
                else if (ie == false) {
                    if ($('.prodsfix').length != 0) {
                        rhs.css({ "margin-left": "571px", "width": "354px" });
                    } else if ($('.looksfix').length != 0) {
                        rhs.css({ "margin-left": "526px", "width": "414px" });
                    } else {
                        rhs.css("margin-left", rhsMarginSmall);
                    }
                }

                // Resize the image gallery

                // Get the current width
                var galleryImgWidth = $('.rhs').css('width').split('px');
                galleryImgWidth = galleryImgWidth[0];

                imgMax = imgMax * 1;
                var galleryHolderWidth = (imgMax + 2) * galleryImgWidth;

                // Set the current margin
                /*thisMarginLeft = (thisURL * (-1 * galleryImgWidth)) + (1 * galleryImgWidth);
                $('#gallery-holder','#image-gallery').css('margin-left',thisMarginLeft + 'px');
				
				$('.gallery-img','#gallery-holder').css('width',galleryImgWidth+'px');
				
				var galleryImgHeight = $('.gallery-img').css('height');
				
				$('#image-holder').css('width', galleryImgWidth+'px');
				
				
				
                $('#gallery-holder').css({
                'width': galleryHolderWidth+'px',
                'margin-left': '-'+galleryImgWidth+'px'
                });
				
				// adjust the heights
                $('#image-holder, #gallery-holder').css('height',galleryImgHeight+'px');
                */



            }

            // IN IE7 set the margin-left
            if (ie7 || ie6) {
                rhs.css("margin-left", "10px");
                $('#content-primary5.rhs').css("margin-left", "0");
            }

            updateContainedItems();
            resizeImageGallery();
            zoomCentreImage();
        }

        // Resize the image gallery
        function resizeImageGallery() {
            // Get the current width
            var galleryImgWidth = $('.rhs').css('width').split('px');
            galleryImgWidth = galleryImgWidth[0];

            imgMax = imgMax * 1;
            var galleryHolderWidth = (imgMax + 2) * galleryImgWidth;

            // Set the current margin
            thisMarginLeft = (thisURL * (-1 * galleryImgWidth)) + (1 * galleryImgWidth);
            // thisMarginLeft = (thisURL * (-1 * galleryImgWidth)) + Math.floor((thisURL / 2) * galleryImgWidth);
            // $('#gallery-holder','#image-gallery').css('margin-left',thisMarginLeft + 'px');

            $('.gallery-img', '#gallery-holder').css('width', galleryImgWidth + 'px');

            var galleryImgHeight = $('.gallery-img').css('height');

            $('#image-holder').css('width', galleryImgWidth + 'px');

            $('#gallery-holder').css({
                'width': galleryHolderWidth + 'px',
                'margin-left': thisMarginLeft + 'px'
            });

            $('#image-cutter').css({
                'width': galleryHolderWidth + 'px',
                'margin-left': '-' + galleryImgWidth + 'px'
            });
            // adjust the heights
            if (galleryImgHeight != 'auto') {
                $('#image-holder, #gallery-holder').css('height', galleryImgHeight + 'px');
            }
            else {
                $('#image-holder, #gallery-holder').css('height', galleryImgHeight);
            }
        }

        function expandMinimise(assign) {
            $('body').addClass('toggled').removeClass('fullwide');

            // Fix the bottom collapsing issue on the image gallery
            $('#image-holder').css('margin-bottom', '0');
            $('ul#nav-gallery').css('bottom', '100px');
            // Helpers
            var isExpand = ($(this).attr("class") == "expand");
            var isMinimize = ($(this).attr("class") == "minimize");
            var isLHS = ($(this).parent().parent().hasClass("lhs"));
            var isRHS = ($(this).parent().parent().hasClass("rhs"));
            var lhsIsSmall = ($(".title-box a", lhs).text() == expText);
            if (assign == '1') {
                rhs.width(bigColOriginal).css({
                    "position": "fixed",
                    "margin-top": "60px",
                    "border-left": "none",
                    "padding-left": "0",
                    'z-index': '12'
                });
                lhs.show();
                toggleSize(false);
                if (ie8) {
                    lhs.css("margin-left", "155px");
                    rhs.css("margin-left", "445px");
                }
            } else if (isExpand && isLHS) {
                toggleSize(true);
            }
            else if (isMinimize && isLHS) {
                toggleSize(false);
            }
            else if (isMinimize && isRHS && !rhs.is(".nomax")) {
                showOnlyNumberTwo(false);

            }
            else if (isMinimize && isRHS && rhs.is(".nomax")) {
                toggleSize(true);
            }
            else if (isExpand && isRHS) {

                // Special case, cover all 3 columns
                if (lhsIsSmall) {
                    showOnlyNumberTwo(true);
                    $('body').addClass('fullwide');
                    if (expandedYet == 0) {
                        $('#header').append('<a class="minimize" href="#">' + minText + '</a><img src="/assets/images/line-hide.jpg" class="hider1" border="0" />');
                        expandedYet = 1;
                    }
                    if (ie7 || ie6) {
                        //
                    }

                } else {

                    toggleSize(false);
                }
            }
            return false;
        }

        /* Update image / title sizes */
        function updateContainedItems() {
            $('body').addClass('updated');

            lhsW = lhs.width();
            rhsW = rhs.width();
            $(".title-box", lhs).width(lhsW + 15);
            $(".title-box", rhs).width(rhsW - 15);

            if (lhs.hasClass("resize-images")) {
                $("img", lhs).each(function() {
                    ratio = lhsW / startSize;
                    s = $.data($(this).get(0), "originalWidth") * ratio;
                    $(this).resizeWidthMaintainRatio(s);
                });
            }

            if (rhs.hasClass("resize-images")) {
                $("img", rhs).each(function() {
                    ratio = lhsW / startSize;
                    s = $.data($(this).get(0), "originalWidth") / ratio;
                    $(this).resizeWidthMaintainRatio(s);
                });
            }

            // Make the expand/minimize buttons say the right thing
            if (lhsW > rhsW || (isSetMaxMin > 0 && lhsW + 75 > rhsW - 75)) {
                $(".title-box a", lhs).text(minText).addClass("minimize").removeClass("expand");
            } else {
                $(".title-box a", lhs).text(expText).addClass("expand").removeClass("minimize");
            }

            if (lhs.is(":hidden") || (rhs.is(".nomax") && lhs.find(".minimize").length == 0)) {
                $(".title-box a", rhs).text(minText).addClass("minimize").removeClass("expand");
            } else {
                $(".title-box a", rhs).text(expText).addClass("expand").removeClass("minimize");
            }
        }

        // Expand/Minimise
        $(".title-box .expand").click(expandMinimise);
        $(".title-box .minimize").click(expandMinimise);

        $("#header .minimize").live("click", function() {
            expandMinimise('1');
            // Fix the bottom collapsing issue
            $('#image-holder').css('margin-bottom', '-1px');
            $('ul#nav-gallery').css('bottom', '100px');
            return false;
        });

        function showOnlyNumberTwo(weWantTo) {
            if (rhs.is(".nomax")) {

            } else {
                if (weWantTo) {
                    lhs.hide();
                    rhs.width(bigColOriginal + 280).css({
                        "margin-left": "155px",
                        "margin-top": "90px",
                        "border-left": "1px solid #bfbfbf",
                        "padding-left": "10px",
                        "position": "relative",
                        'z-index': '0'
                    });

                    // Fix the bottom collapsing issue
                    $('#image-holder').css('margin-bottom', '-1px');
                    $('ul#nav-gallery').css('bottom', '100px');

                } else {
                    if (ie7 || ie6) {
                        // rhs.css("margin-left", "20px");
                        rhs.css("margin-left", rhsMarginBig);
                    }
                    else { rhs.css("margin-left", rhsMarginBig); }
                    rhs.width(bigColOriginal).css({
                        "position": "fixed",
                        "margin-top": "80px",
                        "border-left": "none",
                        "padding-left": "0",
                        'z-index': '12'
                    });
                    lhs.show();
                }
            }
            resizeImageGallery();
            updateContainedItems();
        }
    }

    resizeMe();
    return false;
});

