var $jQuery = jQuery.noConflict(); 


function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, $jQuery('#slide-holder li').length);
    carousel.add(i, $jQuery('#slide-holder li:eq('+(idx - 1)+')').html());
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};



$jQuery(document).ready(function() {
    /** Commented for time being - as clashing with Sitecore preview **/

    $jQuery('ul li#for_remove').remove();

    $jQuery('#mycarousel').jcarouselmod({
        wrap: 'circular',
        itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
        itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
    });



    $jQuery('#fulldetails-carousel').jcarousel({
        vertical: true,
        scroll: 1
    });

    $jQuery('#asset-carousel').jcarousel({
        vertical: true,
        scroll: 1
    });


    $jQuery('#main-menu ul li').hover(
	    function() {
	        var count = $jQuery('ul', this).length;
	        var width = count * 217;
	        $jQuery('.menu-panel', this).width(width + 'px');
	        //alert(width);
	        $jQuery(this).find('div:first:hidden').css({ visibility: 'visible', display: 'none' }).fadeIn(200);
	        $jQuery(this).addClass('ie-over');
	    },
	    function() {
	        $jQuery(this).find('div:first').css({ visibility: 'hidden' });
	        $jQuery(this).removeClass('ie-over');
	    }

	);

	$jQuery('#main-menu ul li:eq(1)').hover(
	    function() {
	        if ($jQuery.browser.msie && $jQuery.browser.version.substr(0, 1) < 7) {
	            // Hide all drop-downs for IE6 and lesser
	            $jQuery('select').hide();
	        }
	    },
	    function() {
	        if ($jQuery.browser.msie && $jQuery.browser.version.substr(0, 1) < 7) {
	            // Show all drop-downs again
	            $jQuery('select').show();
	        }
	    }
	);

});



function popupopen_MyKSLogin() {
	$jQuery('#myks-lightbox-bg').fadeIn(200);
	if ($jQuery.browser.msie && $jQuery.browser.version.substr(0,1)<7) {
		$jQuery('#myks-lightbox-bg').css({position:'absolute', height:$jQuery(document).height()});
		$jQuery('#lightbox-myks-login').css({position:'absolute', top:'400px', left:'50%'});
		DD_belatedPNG.fix('#myks-lightbox-bg, .close, .close a:hover');
		$jQuery('select').fadeOut(200);
	}
}
function popupclose_MyKSLogin() {
	$jQuery('#myks-lightbox-bg').fadeOut(200);
	if ($jQuery.browser.msie && $jQuery.browser.version.substr(0,1)<7) {
		$jQuery('select').fadeIn(200);
	}
}

function popupopen_Contact() {
	$jQuery('#contact-lightbox-bg').fadeIn(200);
	if ($jQuery.browser.msie && $jQuery.browser.version.substr(0,1)<7) {
		$jQuery('#contact-lightbox-bg').css({position:'absolute', height:$jQuery(document).height()});
		$jQuery('#lightbox-contact').css({position:'absolute', top:'400px', left:'50%'});
		DD_belatedPNG.fix('#contact-lightbox-bg, .close, .close a:hover');
		$jQuery('select').fadeOut(200);
	}
}
function popupclose_Contact() {
	$jQuery('#contact-lightbox-bg').fadeOut(200);
	if ($jQuery.browser.msie && $jQuery.browser.version.substr(0,1)<7) {
		$jQuery('select').fadeIn(200);
	}
}

function popupopen_Enquiry(propertyName, contactEmail, propertyDetailsUrl) {
    $jQuery('#contact-lightbox-bg').appendTo("body").fadeIn(200);
    $jQuery('#contact-lightbox-bg').css({ height: $jQuery(document).height() });

    if ($jQuery.browser.msie && $jQuery.browser.version.substr(0, 1) < 7) {
        $jQuery('#lightbox-contact').css({ position: 'absolute', top: '400px', left: '50%' });
        DD_belatedPNG.fix('#contact-lightbox-bg, .close, .close a:hover');
        $jQuery('select').fadeOut(200);
    }

    // Propogate values to the hidden form fields and UI
    $jQuery('#contact-lightbox-field-email input').val(contactEmail);
    $jQuery('#contact-lightbox-label-propertyname').html(propertyName);
    $jQuery('#contact-lightbox-field-propertyname input').val(propertyName);
    $jQuery('#contact-lightbox-field-detailsurl input').val(propertyDetailsUrl);

    // Clear any previously used values we don't need
    $jQuery('#contact-lightbox-bg textarea').each(function(elem) {
        if (this.id.indexOf('txtMessage') > 0) $jQuery(this).val('');
    });
    //    $jQuery('#contact-lightbox-bg input').each(function(elem)
    //    {
    //        if (this.id.indexOf('btnSubmit') == -1) $jQuery(this).val('');
    //    });
}

function popupclose_Enquiry() {
    $jQuery('#contact-lightbox-bg').fadeOut(200);

    if ($jQuery.browser.msie && $jQuery.browser.version.substr(0, 1) < 7) {
        $jQuery('select').fadeIn(200);
    }
}