jQuery.noConflict();

(function ($) {
	$(function () {
				
		$('.please-call-me').change(function () {
			var isChecked = $(this).is(':checked'),
			container = $(this).parents('.callforprice');
			if (isChecked) {
				$('.prefer-phone-call', container).show();
			} else {
				$('.prefer-phone-call', container).hide();
			}
		});
		
		$('.close a').click(function (e) {
			$('.callforpricingouter').hide();
			$(this).parents('.callforprice').fadeOut();
			e.preventDefault();
		});
		
		$('.callforpricingouter').css({
			background: '#000',
			height: $('html, body').height(),
			left: 0,
			position: 'absolute',
			opacity: '.7',
			top: 0,
			width: $(window).width(),
			zIndex: 50
		}).click(function () {
			$('.callforpricingouter').hide();
			$('.callforprice:visible').fadeOut();
		}).hide();
		
		$('.show-pricing-form').click(function (e) {
			var container = $(this).parents('.list_item');
			if (container.length < 1) {
				container = $(this).parents('#customise_buy');
			}
			$('.callforpricingouter').show();
			$('.callforprice', container).css({
				top: 200 + $(window).scrollTop()								  
			}).fadeIn();
			e.preventDefault();
		});
		
		$('.callforpricingform').submit(function (e) {
			var self = $(this),
			html = self.html(),
			button = $('.buttonset input', self);
			$.post('callforpricing.php', self.serialize(), function () {
				self.html('<p>Please check your email for our pricing information.</p>');
				setTimeout(function () {	
					$('.close a').click();
					setTimeout(function () {
						self.html(html);
						button.attr('disabled', '');
					}, 1000);
				}, 3000);
			});
			button.attr('disabled', 'disabled').after('<div class="loading"> Loading...</div>');
			e.preventDefault();
		});
		
	});
}(window.jQuery));


function open_in_popup_window(url, name, width, height) {
	window.open(url.href,name,'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	return false;
}
function open_in_new_window(url) {
	window.open(url.href,'external_link','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	return false;
}
function open_in_popup_window2(url, name, width, height) {
	window.open(url,name,'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	return false;
}
// not animated collapse/expand
function togglePannelStatus(content)
{
    var expand = (content.style.display=="none");
    content.style.display = (expand ? "block" : "none");
    toggleChevronIcon(content);
}

// current animated collapsible panel content
var currentContent = null;

function togglePannelAnimatedStatus(content, interval, step)
{
    // wait for another animated expand/collapse action to end
    if (currentContent==null)
    {
        
		var browser = navigator.appName;
		if( browser=='Netscape') content = content.nextSibling;
		currentContent = content;
        var expand = (content.style.display=="none");
        if (expand)
            content.style.display = "block";
        var max_height = content.offsetHeight;

        var step_height = step + (expand ? 0 : -max_height);
        toggleChevronIcon(content);
                
        // schedule first animated collapse/expand event
        content.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus(" + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
}

function togglePannelAnimatingStatus(interval, step, max_height, step_height)
{
    var step_height_abs = Math.abs(step_height);

    // schedule next animated collapse/expand event
    if (step_height_abs>=step && step_height_abs<=(max_height-step))
    {
        step_height += step;
        currentContent.style.height = Math.abs(step_height) + "px";
        setTimeout("togglePannelAnimatingStatus(" + interval + "," + step
            + "," + max_height + "," + step_height + ")", interval);
    }
    // animated expand/collapse done
    else
    {
        if (step_height_abs<step)
            currentContent.style.display = "none";
        currentContent.style.height = "";
        currentContent = null;
    }
}

// change chevron icon into either collapse or expand
function toggleChevronIcon(content)
{
    var heading = content.parentNode.firstChild.firstChild;
	var browser = navigator.appName;
	if( browser=='Netscape') var heading = content.parentNode.childNodes[1].childNodes[1];
   	if (heading.className == "collapse") heading.className = "";
	else heading.className = "collapse";
}

var moz = document.getElementById && !document.all,
mozHeightOffset = 20;

function resize_iframe () {
	//document.getElementById('brand-intro-container').height = 100 // required for Moz bug, value can be "", null, or integer
	document.getElementById('brands-iframe').height = window.frames['brands-iframe'].document.body.scrollHeight+(moz?mozHeightOffset:0)
}
