$(document).ready(function() {
    //////////////////////////////////////
    //put wheel elements into the container
    ///////////////////////////////////////
    jQuery.each($(".wheelItem"),
        function(indexInArray, wheelItem){
			//create ID fo the element
			var itemID = $(this).text();
			itemID = 'wheelItem' + $.trim(itemID);
			//add element box into container
            var itemHtml = "<div class='item'><div id='"+itemID+"' ></div></div>";
            $("#radial_container .list").append(itemHtml);			
			//add element into box
			$("#"+itemID).append($(this).next().html());			
        }
    );

	
	//remove source
	$(".view-DivisionWheel").remove();
	
	//show images
    $("#radial_container img").each(function() {
        $(this).attr("src", $(this).attr("data-deferredsrc")); 
    });

    //prepare elipse
	jQuery("#radial_container").radmenu({
		listClass: 'list', // the list class to look within for items
		itemClass: 'item', // the items - NOTE: the HTML inside the item is copied into the menu item
		radius: 200, // radius in pixels
		animSpeed:400, // animation speed in millis
		centerX: 270, // the center x axis offset
		centerY: 205, // the center y axis offset
		angleOffset: 0 // in degrees
	});

//EXPERIMENTAL
    //show elipse
    jQuery("#radial_container").radmenu("show");

    //add hover behaviour
    $('.radial_div_item div.images img').hover(function(e){
        //console.log($.browser.version.slice(0,1));
        //console.log($.browser.msie);
        //adjust mouse over animation to current browser
        if ((($.browser.mozilla) && ($.browser.version.slice(0,1)<2)) || ($.browser.msie && ($.browser.version.slice(0,1)<9))){ //if ff older than 4 or msie older than 9
            $(this).css("width", '170px').css("height", '120px');
            $(this).parent().parent().parent().css("z-index", "101");
        } else {
            $(this).hoverFlow(e.type, {
                    width: '170px', height: '120px'
                }, 200, function () {
                    $(this).parent().parent().parent().css("z-index", "101");
                }
            );
        }
    },function(e) {
        //adjust mouse over animation to current browser
        if ($.browser.msie && ($.browser.version.slice(0,1)<9)){ //if msie older than 9
            $(this).css("width", '125px').css("height", '90px');
            $(this).parent().parent().parent().css("z-index", "100");
        }
        else {
            $(this).hoverFlow(e.type, {
                width: '125px',
                height: '90px'
            },200, function () {
                $(this).parent().parent().parent().css("z-index", "100");
            });
        }
    }).click(
        function() {
            var clickedID = $(this).parent().parent().attr("id");
            //$("#popupContent").empty();
            $("#popupContent").html($("#"+clickedID).html());
            $("#popupContent img").css("width", "330px").css("height","230px");
            $("#popupContent .enter a").css("color",jQuery.trim($("#popupContent .enterButton").html()));
            $("#popup").css("background-color",jQuery.trim($("#popupContent .brandColour").html())).css("display","none");
            $("#popup").fadeIn('fast');
        }
    );
    

    ////////////////////
    //prepare menu items
    ////////////////////
    //Our Brands
    jQuery.each($(".view-OurBrandsLinks div.views-field-title"),
        function(){
            var itemID = "wheelItem" + $.trim($(this).next().children().html());
            //console.log(itemID);
            $(this).attr("id", "id_"+itemID);
            //prepare content
            var enterLink = $(this).next().next().children().children().attr("href");
            $("#"+itemID+" .enter a").attr("href", enterLink);

            //listeners
            $(this).hover(
                function(e) {
                    //adjust mouse over animation to current browser
                    var hoverID = $(this).attr("id").split('_', 2)[1];
                    if ((($.browser.mozilla) && ($.browser.version.slice(0,1)<2)) || ($.browser.msie && ($.browser.version.slice(0,1)<9))){ //if ff older than 4 or msie older than 9                        
                        $("#"+hoverID+"  div.images img").css("width", '170px').css("height", '120px');
                        $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "101");
                    } else {                        
                        $("#"+hoverID+"  div.images img").hoverFlow(e.type, {
                            width: '170px',
                            height: '120px'
                        },200, function () {
                            $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "101");
                        });
                    }
                },
                function(e){
                    var hoverID = $(this).attr("id").split('_', 2)[1];
                    //adjust mouse out animation to current browser
                    if ($.browser.msie && ($.browser.version.slice(0,1)<9)){ //if msie older than 9
                        $("#"+hoverID+"  div.images img").css("width", '125px').css("height", '90px');
                        $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "100");
                    } else {
                        $("#"+hoverID+"  div.images img").hoverFlow(e.type, {
                            width: '125px',
                            height: '90px'
                        },200, function () {
                            $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "100");
                        });
                    }
                }
            ).click(
                function() {
                    var clickedID = $(this).attr("id").split('_', 2)[1];
                    //$("#popupContent").empty();
                    $("#popupContent").html($("#"+clickedID).html());
                    $("#popupContent img").css("width", "330px").css("height","230px");
                    $("#popupContent .enter a").css("color",jQuery.trim($("#popupContent .enterButton").html()));
                    $("#popup").css("background-color",jQuery.trim($("#popupContent .brandColour").html())).css("display","none");
                    $("#popup").fadeIn('fast');
                }
            );
        }
    );
    //Value added
    jQuery.each($(".view-ValueAddedLinks div.views-field-title"),
        function(e){
            var itemID = "wheelItem" + $.trim($(this).next().children().html());
            //console.log(itemID);
            $(this).attr("id", "id_"+itemID);
            $(this).hover(
                function(e) {
                    //adjust mouse over animation to current browser
                    var hoverID = $(this).attr("id").split('_', 2)[1];
                    if ((($.browser.mozilla) && ($.browser.version.slice(0,1)<2)) || ($.browser.msie && ($.browser.version.slice(0,1)<9))){ //if ff older than 4 or msie older than 9
                        $("#"+hoverID+"  div.images img").css("width", '170px').css("height", '120px');
                        $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "101");
                    } else {
                        $("#"+hoverID+"  div.images img").hoverFlow(e.type, {
                            width: '170px',
                            height: '120px'
                        },200, function () {
                            $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "101");
                        });
                    }
                },
                function(e){
                    var hoverID = $(this).attr("id").split('_', 2)[1];
                    //adjust mouse out animation to current browser
                    if ($.browser.msie && ($.browser.version.slice(0,1)<9)){ //if msie older than 9
                        $("#"+hoverID+"  div.images img").css("width", '125px').css("height", '90px');
                        $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "100");
                    } else {
                        $("#"+hoverID+"  div.images img").hoverFlow(e.type, {
                            width: '125px',
                            height: '90px'
                        },200, function () {
                            $("#"+hoverID+"  div.images img").parent().parent().parent().css("z-index", "100");
                        });
                    }
                }
            ).click(
                function() {
                    var clickedID = $(this).attr("id").split('_', 2)[1];
                    //$("#popupContent").empty();
                    $("#popupContent").html($("#"+clickedID).html());
                    $("#popupContent img").css("width", "330px").css("height","230px");
                    $("#popupContent .enter a").css("color","#06a5ee");
                    $("#popup").css("background-color","#06a5ee").css("display","none");
                    $("#popup").fadeIn('fast');
                }
            );
        }
    );

    //create pop up window
    $("#main .content").append("<div id='popup'><div id='popupContent'></div></div>");

    //close popup window on click
    $("#popup").click(
        function() {
            $(this).css("display","none");
        }
    );

	//remove origo online item from products submenu
	$("div#nav-inner ul#superfish-1.sf-menu  li#menu-4107-1").remove();
});

