var pageid = 0;

//GetQueryString('nav');
function GetQueryString(key){
    var url = location.href, key = key.toLowerCase();
    val = "";
    var qString = "";
    if (url.indexOf("?") != -1) {
        qString = url.split("?")[1];
    }
    
    if (qString != "" && key != "") {
        var arrQStringKeyValue = (qString.indexOf("&") != 1) ? qString.split("&") : qString;
        if (arrQStringKeyValue.length > 1) {
            for (i = 0; i < arrQStringKeyValue.length; i++) {
                var temp = arrQStringKeyValue[i].toLowerCase();
                if (temp.indexOf(key) != -1) {
                    if (arrQStringKeyValue[i].indexOf("=") != -1) {
                        arrKeyVal = arrQStringKeyValue[i].split("=");
                        temp = arrKeyVal[0].toLowerCase();
                        val = (temp == key) ? arrKeyVal[1] : "";
                    }
                }
            }
        }
        else {
            var temp = arrQStringKeyValue[0].toLowerCase();
            if (temp.indexOf(key) != -1) {
                if (arrQStringKeyValue[0].indexOf("=") != -1) {
                    arrKeyVal = arrQStringKeyValue[0].split("=");
                    temp = arrKeyVal[0].toLowerCase();
                    val = (temp == key) ? arrKeyVal[1] : "";
                }
            }
        }
    }
    
    // Remove anything after #
    val = (val.indexOf("#") != -1) ? val.split("#")[0] : val;
    return val;
}

$(document).ready(function () {
    $('#MainNav').addClass('NavActive');
    //Nav Menu Function
    $('.NavActive li').squeakyNavMenu();
    $('.NavActive li:first').addClass('NoBorder');
    $('#MainNav li a:first').css({
        marginLeft: '0'
    });
    $('#MainNav li a:last').css({
        marginRight: '0'
    });

    //AddThis Drop Down
    $('.custom_button, .hover_menu').mouseenter(function () {
        $('.hover_menu').fadeIn('fast');
        $('.custom_button').addClass('active');
        $(this).data('in', true);
        $('.hover_menu').data('hidden', false);
    }).mouseleave(function () {
        $(this).data('in', false);
        setTimeout(hideMenu, delay);
    });

    var delay = 400;
    function hideMenu() {
        if (!$('.custom_button').data('in') && !$('.hover_menu').data('in') && !$('.hover_menu').data('hidden')) {
            $('.hover_menu').fadeOut('fast');
            $('.custom_button').removeClass('active');
            $('.hover_menu').data('hidden', true);
        }
    }

    //No Border on last Li for AddThis Drop down menu
    $('.hover_menu ul li:last-child').addClass('NoBorder');
	
	//Lifestyle panel Value Update Values When New Artical is added
	var obj  = {
		panelValuePowell: "1", 
		panelValueGrant: "1", 
		panelValueBanner: "1", 
		panelValueBeaty: "1", 
		panelValuePeters: "2", 
		panelValueJohnson: "2", 
		panelValueGreen: "2", 
		panelValueSamuels: "2", 
		panelValueMonyee: "3", 
		panelValueGetaways:"3" , 
		panelValueGames:"3",
		panelValueHBCU:"3",
		panelValueLAF:"4",
		panelValueResorts:"4",
		panelValueFlight:"4",
		panelValueCaribbean:"4",
		panelValueISC:"5",
		panelValueBuying:"5",
		panelValueRX:"5",
		panelValueSizzles:"5",
		panelValueHS:"6",
		panelValueCreme:"6",
		panelValueSleeve:"6",
		panelValueScreen:"6",
		panelValueCulture:"7"
		};
	$.each( obj, function(k, v){
			
		$("a." + k).attr('href', '/lifestyle/index.aspx?nav=Scroll#' + v);
		
	 });
			
    //Side Bar Matching
    var strBodyClass = $("body").attr('class'), sideBarList = $('#LuxuryCallout li h5'), multiple = 0, arrClass = '', found = false, strBodyClass = $.trim(strBodyClass);
    if (strBodyClass.indexOf(" ") != -1) {
        multiple++;
        arrBodyClass = strBodyClass.split(" ");
    }

    if (strBodyClass != '') {
        if (multiple == 0) {
            for (j = 0; j < sideBarList.length; j++) {
                if ($(sideBarList[j]).attr('id') != ('Title' + strBodyClass)) {
                    $(sideBarList[j]).parent().css({
                        display: 'block'
                    });
                }
            }
        }
        else {
            for (i = 0; i < arrBodyClass.length; i++) {
                for (j = 0; j < sideBarList.length; j++) {
                    if ($(sideBarList[j]).attr('id') != ('Title' + arrBodyClass[i])) {
                        $(sideBarList[j]).parent().css({
                            display: 'block'
                        });
                    }
                    else {
                        found = true;
                    }
                }
                if (found) {
                    break;
                }
            }
        }
    }

    //Feature Photos Hover effect Hover function for "A" tag
    $('#FeaturePhotos li a.TransparentImg').css({
        opacity: 0.7
    });
    $('#FeaturePhotos li a.TransparentImg').hover(function () {
        $(this).stop().animate({
            opacity: 1
        }, '600');
    }, function () {
        $(this).stop().animate({
            opacity: 0.7
        }, '400');
    });

    //Feature Photos Hover effect Hover function for nested "div" tag	
    $('#FeaturePhotos li div').hover(function () {
        $(this).prev('a.TransparentImg').stop().animate({
            opacity: 1
        }, '600');
    }, function () {
        $(this).prev('a.TransparentImg').stop().animate({
            opacity: 0.7
        }, '400');
    });

    //Pop Up Window for Photos
    if ($('a.PopUp').length > 0) {
        $('a.PopUp').click(function () {
            CallSimpleModalPhotos($.trim($(this).attr('rel')));
        });
    }

    function CallSimpleModalPhotos(src) {
        $.modal('<iframe src="/photo-albums/' + src + '" height="520" width="720" style="border:0px;" frameborder="0" scrolling="no">', {
            closeHTML: "<a href='#'></a>",
            containerCss: {
                height: 520,
                padding: 0,
                width: 720
            }
        });
    }

    //Pop Up Window for Videos
    if ($('a.PopUpVideo').length > 0) {
        $('a.PopUpVideo').click(function () {
            CallSimpleModalVideo($.trim($(this).attr('rel')));
        });
    }

    function CallSimpleModalVideo(src) {
        $.modal('<iframe src="/video-albums/' + src + '" height="505" width="690" style="border:0px;" frameborder="0" scrolling="no">', {
            closeHTML: "<a href='#'></a>",
            containerCss: {
                height: 505,
                padding: 0,
                width: 690
            }
        });
    }

    //Pop Up for Music File
    if ($('a.PopUpMusic').length > 0) {
        $('a.PopUpMusic').click(function () {
            CallSimpleModalMusic($.trim($(this).attr('rel')));
        });
    }

    function CallSimpleModalMusic(src) {
        //alert(src);
        $.modal('<iframe src="/mp3-albums/' + src + '" height="155" width="690" style="border:0px;" frameborder="0" scrolling="no">', {
            closeHTML: "<a href='#'></a>",
            containerCss: {
                backgroundColor: '#292932',
                height: 155,
                paddingTop: 0,
                width: 690
            }
        });
    }

    //Pop Up for Hal Linto Music File
    if ($('a.PopUpMusic2').length > 0) {
        $('a.PopUpMusic2').click(function () {
            CallSimpleModalMusic2($.trim($(this).attr('rel')));
        });
    }

    function CallSimpleModalMusic2(src) {
        $.modal('<iframe src="' + src + '" height="380" width="500" style="border:0px;" frameborder="0" scrolling="no">', {
            closeHTML: "<a href='#'></a>",
            containerCss: {
                backgroundColor: '#292932',
                height: 400,
                paddingTop: 25,
                width: 520
            }
        });
    }
    //Pop Up for CT Music File
    if ($('a.PopUpMusic3').length > 0) {
        $('a.PopUpMusic3').click(function () {
            CallSimpleModalMusic3($.trim($(this).attr('rel')));
        });
    }

    function CallSimpleModalMusic3(src) {
        //alert(src);
        $.modal('<iframe src="/mp3-albums/' + src + '" height="370" width="590" style="border:0px;" frameborder="0" scrolling="no">', {
            closeHTML: "<a href='#'></a>",
            containerCss: {
                backgroundColor: '#292932',
                height: 370,
                paddingTop: 0,
                width: 590
            }
        });
    }

    //Leaving Site Message
    $(function ($) {
        $('a.LeavingSite').click(function (e) {
            e.preventDefault();
            fireTag(2247.1, {
                '<nav_method>': 'Other'
            });
            var urlToRedirect = $(this).attr('href');
            confirm("<img src='/images/Title-Your-are-leaving-Luxuryawaits.com.gif' width='314' height='19' alt='You are now leaving Luxur Awaits' />", function () {
                window.open(urlToRedirect);
            });
        });
    });

    function confirm(message, callback) {
        $('#confirm').modal({
            closeHTML: "<a href='#' title='Close'></a>",
            position: ["20%", ],
            overlayId: 'confirm-overlay',
            containerId: 'confirm-container',
            onShow: function (dialog) {
                $('.message', dialog.data[0]).append(message);
                $('.yes', dialog.data[0]).click(function () {
                    if ($.isFunction(callback)) {
                        callback.apply();
                    }
                    $.modal.close();
                });
            }
        });
    }

    //Leaving Site CT Remix Message
    $(function ($) {
        $('a.CTRmixSite').click(function (e) {
            e.preventDefault();
            fireTag(2247.1, {
                '<nav_method>': 'Other'
            });
            var urlToRedirect = $(this).attr('href');
            confirm2(function () {
                window.open(urlToRedirect);
            });
        });
    });

    function confirm2(callback) {
        $('#confirm-ct-remix').modal({
            closeHTML: "<a href='#' title='Close'></a>",
            position: ["20%", ],
            overlayId: 'confirm-overlay',
            containerId: 'confirm-container',
            onShow: function (dialog) {
                $('.yes', dialog.data[0]).click(function () {
                    if ($.isFunction(callback)) {
                        callback.apply();
                    }
                    $.modal.close();
                });
            }
        });
    }

    //Gallery Slide Show Photos
    if ($('#PhotosSlideShow, #VideosSlideShow').length > 0) {
        $('#PhotosSlideShow').jcarousel({
            scroll: 3,
            initCallback: carouselphotos_initCallback,
            //isPagingOn: true,
            pagingSelector: '.jcarousel-control-photo a',
            pagingClass: 'On'
        });
        $('#VideosSlideShow').jcarousel({
            scroll: 3,
            initCallback: carouselvideos_initCallback,
            //isPagingOn: true,
            pagingSelector: '.jcarousel-control-videos a',
            pagingClass: 'On'
        });
    }

    //Homepage slider
    if ($('#FeaturePhotoStrip').length > 0) {
        $('#FeaturePhotoStrip').jcarousel({
            scroll: 3,
            pagingSelector: '.jcarousel-control-photo a',
            pagingClass: 'On'
        });
    }

    //Content Slider For Lexus Lineup Section
    if ($('#coda-slider-1').length > 0) {
        $('#coda-slider-1').codaSlider({
            isLexus: true,
            isFireTag: true,
            isLexusTabs : true,
            fireId: 2242.1
        });
    }

    //Content Slider For LifeStyle Section
    if ($('#coda-slider-2').length > 0) {
        $('#coda-slider-2').codaSlider({
            isLexus: true,
            isFireTag: true,
            isLexusTabs : true,
            fireId: 2244.1
        });
    }
	
	//Content Slider For Events Section
    if ($('#coda-slider-3').length > 0) {
        $('#coda-slider-3').codaSlider({
        	isLexus: true,
        	isLexusTabs : true
        });
    }
	
	//Content Slider For Press Section
    if ($('#coda-slider-4').length > 0) {
        $('#coda-slider-4').codaSlider({
        	isLexus: true,
        	isLexusTabs : true
        });
    }
	
    //Content Scroll Bar for Lifestyle Section
    if ($('#pane1').length > 0) {
        $('#pane1').jScrollPane({
            topCapHeight: 25
        });
    }

    //Content Scroll for Access Graned Section
    if ($('#pane2').length > 0) {
        $('#pane2').jScrollPane();
    }

    //Content Scroll for Anchor Tags
    if ($('#pane3').length > 0) {
        var $pane3 = $('#pane3');
        $pane3.jScrollPane({
            topCapHeight: 25,
            animateTo: true,
            animateInterval: 50
        });
        $('a.scroll-to-element').bind('click', function () {
            var targetElementSelectorString = $(this).attr('rel');
            $pane3[0].scrollTo(targetElementSelectorString);
            return false;
        });
    }

    //Last Schedule Item
    $('#ScheduleList li:first').css({
        paddingTop: '0'
    });
    $('#ScheduleList li:last').addClass('Last');
	
	 //Facebook taging 
   $('.addthis_button_facebook').click(function(){
		 var fbContent = $.trim($('title').text());
	    fireTag(2240.2, {
	        '<share_type>': 'Facebook',
	        '<share_content>': fbContent
	    });
	});
	
    //Copyright
    var current_date = new Date();
    year_value = current_date.getFullYear();
    $('#CopyRight').html("&copy; " + year_value + " Lexus, A Division of Toyota Motor Sales, U.S.A, Inc.");

    //Footer No Border for Last Li of each Ul
    $('#Footer ul').each(function () {
        $(this).find('li:last-child').addClass('NoBorder').css({
            marginBottom: '0'
        });
    });
    //INDEX
    if ($('#FeaturePhotosView').length > 0) {
        $('#FeaturePhotosView li').eq(0).show();
        $('#FeaturePhotoStrip li').click(function () {
            $('#FeaturePhotosView li').hide();
            $('#FeaturePhotosView li').eq($(this).index()).fadeIn();

        });
    }
   
	if($('#FeaturePhotos').length > 0) {
		if (!isMobileBrowser){
			$('.jcarousel-prev,.jcarousel-next').hide();
		}
		
		var config = {
			over : showMenu,
			timeout : 100,
			out : hideMenuCarousel
		};
		
		$("#FeaturePhotos").hoverIntent(config);
	}
	//Hover event for Arrows on home page 
		function showMenu() {
			$(".jcarousel-prev,.jcarousel-next").fadeIn();

		}

		function hideMenuCarousel() {
			$(".jcarousel-prev,.jcarousel-next").fadeOut()
		}	
});

/* 
 -- Jquery Functions End --
 --Add this Functions Start Below--
 */
//Add This Click Back Functions
var addthis_config = {
    data_track_clickback: true
}

//Twitter Add this Functions
function GetFirstSentence(str){
    var strFirstSentence = "";
    if (str.indexOf(".") != -1) {
        strFirstSentence = str.substr(0, str.indexOf(".")) + ".";
    }
    else {
        strFirstSentence = str + ".";
    }
    return strFirstSentence;
}

function GetMetaDesc(){
    var arrMetaDesc = $('meta[name="description"]');
    var metaDesc = '';
    if (arrMetaDesc.length > 0) {
        metaDesc = GetFirstSentence(arrMetaDesc[0].getAttribute('content'));
    }
    return metaDesc;
}

var twitterTempDesc = GetMetaDesc() + ' {{url}} from luxuryawaits.com';
var addthis_share = {
    templates: {
        twitter: twitterTempDesc
    }
}

function callTwitterFireTag(){  
    return true;
}

// Alert a message when the user shares somewhere
function addThisEventHandler(evt){
    switch (evt.type) {
        case "addthis.menu.share":
            if (evt.data.service == "twitter") {
                var twContent = GetMetaDesc();
                fireTag(2240.2, {
                    '<share_type>': 'Twitter',
                    '<share_content>': twContent
                });
            }
            break;
        default:
    }
}

// Listen to various events
addthis.addEventListener('addthis.menu.share', addThisEventHandler);

