$(document).ready(function () {

//highlight nav
    var Home = "homepage";
	var Movies = "panelgroup_moviespage";
	var MoviesDetail = "movie/";
	var Games = "panelgroup_gamespage";
	var GamesDetail = "game/";
    var Music = "panelgroup_musicpage";
	var MusicDetail = "music/";
	var Electronics = "panelgroup_electronicspage";
	var ElectronicsDetail = "electronic/";
    var Phones = "panelgroup_phonespage";
	var PhonesDetail = "phone/";
	var Cinema = "panelgroup_incinema";//too many pages, use else statement instead
    var News = "panelgroup_newsandgossippage";
    var url = window.location.href.toLowerCase();
	
	MoviesDetail
    if( (url.indexOf(MoviesDetail) >= 0) || (url.indexOf(Movies) >= 0) ) {
	   $('#top_dvd a').attr('id', 'top_dvd_selected'); 
    } 
	else if ( (url.indexOf(Games) >= 0) || (url.indexOf(GamesDetail) >= 0) ) {
		$('#top_games a').attr('id', 'top_games_selected'); 
	}
	else if ( (url.indexOf(Music) >= 0) || (url.indexOf(MusicDetail) >= 0) ) {
		$('#top_music a').attr('id', 'top_music_selected'); 
	}
	else if ( (url.indexOf(Electronics) >= 0) || (url.indexOf(ElectronicsDetail) >= 0) ) {
		$('#top_electronics a').attr('id', 'top_electronics_selected'); 
	}
	else if ( (url.indexOf(Phones) >= 0) || (url.indexOf(PhonesDetail) >= 0) ){
		$('#top_phones a').attr('id', 'top_phones_selected'); 
	}
	else if (url.indexOf(News) >= 0){
		$('#top_news a').attr('id', 'top_news_selected'); 
	}
	else if (url.indexOf(Home) >= 0){
		//Home page has no active menu item
	}
	else {
		//The incinema section has no common page name so its best to be the else

	}

    // homepage tabs
    $(".home-tabs:first").tabs(".home-panes:first > div", { effect: 'fade', fadeOutSpeed: 500, rotate: true }).slideshow({ autoplay: true, interval: 4000 });
    $(".scrollable-tabs").tabs(".scrollable-panes > div");

    //scrollers
    $(".scroller").scrollable({ circular: true, mousewheel: true });
    $(".promo-slider").scrollable({ circular: true, mousewheel: true }).navigator().autoscroll({ autoplay: true });

    var naviwidth = $(".navi").width();
    var navileft = Math.ceil((379 - naviwidth) / 2);
    $(".navi").css('padding-left', navileft);

    //change the class on the first LI element of each UL to remove the top border
    $("#menu li ul li:first-child").addClass("first");

    //hide all side nav except the highlighted one
    $("#menu li:not(.highlight)").addClass("hidden");

    //on click show/hide
    $("#menu li").click(function () {
        if (!($(this).hasClass("highlight"))) {
            $(".highlight ul").slideUp();
            $(".highlight").removeClass("highlight");
            $(this).addClass("highlight");
            $(this).find("ul").slideDown();
        }
    });

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li").click(function () {

        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });


    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'light_square'
    });


    $('.image_gallery li').hover(function () {
        $(this).find('span.play').toggle();
    });

    $('#side.moviedetail .side_links li').hover(function () {
        $(this).find('span.playtrailer').toggle();
    });

    $('.image_box li').hover(function () {
        $(this).find('span.playtrailer').toggle();
    });

});

