$(document).ready(function() {
		
	//login area show hide --------------------------------------------------------
	
	$("#loginPanel").hide();
	
	$(".login").click(function() {
		$("#loginPanel").slideToggle("fast");
	});
	
	
	//primary links image-based hover states --------------------------------------
	
	$('#primaryLinks a')
		.css( {backgroundPosition: "0 -120"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -120)"}, {duration:800})
	})
		
	$('.home ul li#home a')
		.css( {backgroundPosition: "0 -45"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -45)"}, {duration:500})
	})
		
	$('.philosophy ul li#philosophy a')
		.css( {backgroundPosition: "0 -45"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -45)"}, {duration:500})
	})
		
	$('.clients ul li#clients a')
		.css( {backgroundPosition: "0 -45"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -45)"}, {duration:500})
	})
	
		
	
	// Sidebar image based hover states --------------------------------------------
	
	$('#sideBar .subLinks ul li a')
		.css( {backgroundPosition: "0 -2"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -90px)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -2)"}, {duration:300})
	})
		
	$('#sideBar .subLinks ul li.active a')
		.css( {backgroundPosition: "0 -70"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -90px)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -70)"}, {duration:300})
	})
	
	
	// setting quicklinks based on login status ------------------------------------
	
	$(function () {
		if (login_flag == 0)
		{
				$('#webreports_id').replaceWith("<li><a href='#' class='loginAlert'>Online Reporting</a></li>");
				$('#salesatlas_id').replaceWith("<li><a href='#' class='loginAlert'>Sales Atlas</a></li>");
				$('#updateaccount_id').hide();
				$('#logout_id').hide();	
		}
		
		else if (login_flag == 1)
		{
				
				$('#login_id').hide();	
		}
	});
	
	
	// login tooltip error message - using jQueryTools------------------------------------------------
	
	$(".loginAlert").tooltip({
		 
		 tip: '#tooltip',
		 position: ['bottom', 'center'],
		 effect: 'slide',
		 slideInSpeed: 300,
		 slideOutSpeed: 150,
		 bounce: 'true',
		 offset: [25, 0],
		 delay: 0
	});
	
	
	
	//Adding zebra striping to tables (this doesn't control the ROI Report tables, see myTableSorter.js for that)

	$(function(){
		$("table.details tr:even").addClass("even");
		$("table.details tr:odd").addClass("odd");
	});

	
	// setting visibility of Report Links based on group level and access level  -----------
	
	// online reporting page links
        $('#PURLReportLink').hide();
        $('#salesROILink').hide();
        $('#serviceROILink').hide();
        $('#groupSalesROILink').hide();
        $('#groupServiceROILink').hide();
        $('#statusReportLink').hide();        $('#bLinkedReportLink').hide();
        $('#bLinkedReportSampleLink').hide();
                    
        // quick links menu
        $('#menuPURLReportLink').hide();
        $('#menuSalesROILink').hide();
        $('#menuServiceROILink').hide();
        $('#menuGroupSalesROILink').hide();
        $('#menuGroupServiceROILink').hide();
        $('#menuStatusReportLink').hide();
        $('#menuBLinkedReportLink').hide();
        $('#menuBLinkedReportSampleLink').hide();
                    
        $(function(){
                if (sales_access == 1) // User has permission to view sales report data
                {
                    if (company_group_num == 0 && company_id > 0) // Single company report
                    {
                        $('#salesROILink').show();
                        $('#menuSalesROILink').show();
                    }
                    if (company_group_num > 0) // Group company report
                        {
                        $('#menuGroupSalesROILink').show();
                        $('#groupSalesROILink').show();
                        }
                }
        	
                if (service_access == 1) // User has permission to view service report data
                {
                        if (company_group_num == 0 && company_id > 0) // Single company report
                        {
                            $('#serviceROILink').show();
                            $('#menuServiceROILink').show();
                            }
                            if (company_group_num > 0) // Group company report
                        {
                                $('#menuGroupServiceROILink').show();
                                $('#groupServiceROILink').show();
                                }
                }
                        
                if (purl_access == 1) // User has permission to view PURL report data
                {
                        //if (company_group_num > 0 || company_id > 0 || customer_type == 4) // PURL report
                        //{
                                $('#PURLReportLink').show();
                                $('#menuPURLReportLink').show();
                                //}
                }
                
                if (statusreport_access == 1) // User has permission to view Status report data
                {
                        //if (company_group_num > 0 || company_id > 0 || customer_type == 4) // Status report
                        //{
                                $('#statusReportLink').show();
                                //$('#menuStatusReportLink').show();
                                //}
                }
                
                if (blinked_access == 1) // User has permission to view bLinked report data
                {
                        //if (company_group_num > 0 || company_id > 0 || customer_type == 4) // bLinked report
                        //{
                                $('#bLinkedReportLink').show();
                                //$('#menuBLinkedReportLink').show();
                                if (customer_type == 4) // J&L Employee                                {
									$('#bLinkedReportSampleLink').show();	                                //$('#menuBLinkedReportSampleLink').show();
								}
                        //}
                }
                if (purl_access == 0 && sales_access == 0 && service_access == 0 && statusreport_access == 0 && blinked_access == 0)
                {
                    $('#reportingLinksMenu').hide();	
                }
        });
        		
	
	// Determining whether or not to show the group select div on the group reports page. This div contains a list that allow users with access to multiple groups to view links to those other groups. In BMW's case we would be dealing with the different regions.
	
	$('#groupSelect').hide(); // start off by hiding the group select area by default
	
	$(function () {
		if (parent_id == 0 || parent_id == -1 || customer_type == 4) // 0 means we are dealing with a top level account, -1 is a contact with access to multiple groups but in not a top level account, any other number means user have access to one group only. Customer Type of 4 means we are dealing with a J&L employee.
			{
				$('#groupSelect').show(); //show the group select div
			}
	});	
	
});
