$.extend({ lock: function(count, callback) { var count = count; return function(e) {if (--count == 0) callback();} }, isIE6: function() {return (($.browser.msie) && ($.browser.version == 6.0));} }); $.fn.extend({ ie6TransparentImage: function() { return this.each(function() { var div = $(document.createElement('div')); div.css({ 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + $(this).attr('src') + "', sizingMethod='crop');", 'width': $(this).attr('width') + 'px', 'height': $(this).attr('height') + 'px' }).attr('id', $(this).attr('id')); $(this).replaceWith(div); }); }, ie6TransparentBackground: function() { return this.each(function() { var re = /url\("http:\/\/[^\/]*([^"]*)"\)/; m = re.exec($(this).css('background-image')); if (m != null) { $(this).css({ 'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + m[1] + "', sizingMethod='crop');", 'backgroundImage': 'none' }); } }); } }); var swapper = function() { var sw_url = null; var sw_stem = ''; var sw_callback = null; var sw_complete = null; var data = null; var current = 0; var sw_links_per_item = 1; function init(url, stem, callback, completed_callback, links_per_item) { sw_url = url; sw_stem = stem; sw_callback = callback; sw_complete = completed_callback; if (links_per_item) sw_links_per_item = links_per_item; selectLink(); $('#' + sw_stem).hide(); $('#panel.' + sw_stem + 's li a').each(updateLink); $.getJSON(sw_url, function(d) { data = d; update(); }); } function click(e, index) { current = Math.floor(index / sw_links_per_item); selectLink(); $('#reg_form').fadeOut('slow'); if ($('#reg').length > 0) { var lk = $.lock(2, update); $('#reg').fadeOut('slow', lk); $('#' + sw_stem).fadeOut('slow', lk); } else { $('#' + sw_stem).fadeOut('slow', update); } } function updateLink(index) { $(this).attr('href', 'javascript:void(0);') .bind('click', function(e) {click(e, index);}); } function selectLink() { $('#panel.' + sw_stem + 's li').removeClass('selected'); $($('#panel.' + sw_stem + 's li')[current]).addClass('selected'); } function update() { if (data == null) return; var c = sw_callback(data, current); $('#' + sw_stem).html(c); if (sw_complete) sw_complete(); else $('#' + sw_stem).fadeIn('slow'); } return { init: init } }(); var RegForm = function() { var vis = false; function set_current(c) { $('#reg_form .dev_id').attr('value', c); } function toggle() { if (vis) { vis = false; $('#reg_form').fadeOut('slow'); } else { vis = true; $('#reg_form').fadeIn('slow'); } } return { toggle: toggle, set_current: set_current } }(); $(function(){ function checkInput(id) { var x = $($(id).get(0)); var y = $(x.closest('div').get(0)); if (x.val() == '') { y.addClass('error'); return false; } y.removeClass('error'); return true; } function checkForm() { var valid = true; if ($('#reg_form .dev_id').length == 0) { if ($('#register .checkbox input:checked').length == 0) { $('#register .checkbox').addClass('error'); valid = false; } else $('#register .checkbox').removeClass('error'); } valid = (checkInput('#name') && valid); valid = (checkInput('#email') && valid); return valid; } if ($.isIE6()) $('.filter').ie6TransparentBackground(); if ($('#content.c_directors').length) { swapper.init('assets/data/directors.json', 'director', function(data, current) { return '
' + data[current].name + '
' + '
' + data[current].title + '
' + '
' + data[current].prose + '
'; }, null, 2); } if ($('#content.c_past').length) { swapper.init('assets/data/past_developments.json', 'development', function(data, current) { var image_link = data[current].slug.toLowerCase().replace(/ /g, '_'); return '
' + '
' + data[current].name + '
' + '
' + data[current].address + '
' + '
' + data[current].prose + '
' + '
' + ''; }); } if ($('#content.c_northern').length) { swapper.init('assets/data/northern.json', 'development', function(data, current) { var image_link = data[current].slug.toLowerCase().replace(/ /g, '_'); return '
' + '
' + data[current].name + '
' + '
' + data[current].prose + '
' + '
' + ''; }, function() { $('#reg').hide().html('View the Shillington Grove brochure'); $('#development').fadeIn('slow'); $('#reg').fadeIn('slow'); }); } if ($('#content.c_london').length) { swapper.init('assets/data/london.json', 'development', function(data, current) { RegForm.set_current(current); var image_link = data[current].slug.toLowerCase().replace(/ /g, '_'); return '
' + '
' + data[current].name + '
' + '
' + data[current].prose + '
' + '
' + ''; }, function() { $('#development').fadeIn('slow'); $('#reg').hide().fadeIn('slow'); }); var a = $(document.createElement('a')); a.text('Click here to register interest'); a.attr('href', 'javascript:void(0);'); a.bind('click', function(e) { RegForm.toggle(); }); $('#reg').html(a); $('form').bind('submit', checkForm); } if ($('#content.c_terms').length) { $('#terms .inner').jScrollPane(); } if ($('#content.c_home').length) { var lh = $('#news .left').height(); var rh = $('#news .right').height(); var mh = (lh>rh)?lh:rh; $('#newsbg').height(mh + 40); $('form').bind('submit', checkForm); } });