
var portfolio={
    ITEMS_IN_PANEL: 16,
    itemsCountInCategory: [0, 0, 0, 0, 0],
    items: [[], [], [], [], []], // items devided per category
    pathPrefixes: [
        'portfolio/portf_websites/',
        'portfolio/portf_interf/',
        'portfolio/portf_print/',
		'portfolio/portf_illustration/',		
        'portfolio/portf_photo/'
    ],
    pictureIndex: 0,
    sectionNames: ['website_panel', 'interface_panel', 'graphic_panel', 'illustration_panel', 'photography_panel'],
    sectionTitles: ['WEBSITE', 'INTERFACE', 'GRAPHIC DESIGN', 'ILLUSTRATION', 'PHOTOGRAPHY'],
    topLineColors: ['FC76DC', '87C542', 'F5A736', 'cc2e31', '44C3D2' ], // colors of the top line

    setup:function(){
	        portfolio.addItem('22_nuenergen', "NuEnergen", "NuEnergen", "Design and implementation on Concrete 5 informational portal about the company and it's services", 'nuenergen.com', 1);	   
	        portfolio.addItem('21_sigma6', "Lin Six Sigma", "Lin Six Sigma", "Design of web-portal for company that provides Six Sigma training", null, 1);	   
          portfolio.addItem('01_desound1', "Desound", "Desound", "Design of web-portal for company that provides exclusive acoustic systems", null, 1);	   
          portfolio.addItem('01_desound2', "Desound (accepted)", "Desound (accepted)", "Design of the web-portal for company that provides exclusive acoustic systems (accepted variant) (during development...)", 'desound.nichost.ru', 1);	   
	        portfolio.addItem('20_multitech', "Multitech", "Multitech", "Design of web portfolio for company that provides web development services", null, 1);	   
	        portfolio.addItem('19_prabhupada', "Prabhupada", "Prabhupada", "Design of online resource with full collection of Prabhupada's lectures in Russian", 'prabhupada.ru', 1);	             
	        portfolio.addItem('01_uttama_sloka', "Uttama Sloka", "Uttama Sloka", "Design of personal website for spiritual leader (during development...)", null, 1);
          portfolio.addItem('01_inveda', "Inveda", "Inveda", "Design and assembling of the site for the Center of Vedic Culture in the Moscow", 'inveda.ru/', 1);
	        portfolio.addItem('01_basel', "Basel", "Basel", "Design of the web-portal for commercial real estate company", 'basel-realty.ru', 1);	   			
          portfolio.addItem('01_mary_kay', "Mary Kay", "Mary Kay", "Design of website for consultant of Mary Kay Company", null, 1);	
          portfolio.addItem('01_greator', "Qreator", "Qreator Studio", "Design of website for web studio", 'www.qreator.com', 1);
          portfolio.addItem('02_moshurov1', "Moshurov", "Moshurov", "Design of website for Food Factory Moshurov", null, 1);
          portfolio.addItem('03_geksagon', "Geksagon", "Geksagon", "Design of website for bar coding company", null, 1);
          portfolio.addItem('04_beat_india', "The Beatles & India", "The Beatles & India", "Design of website for Moscow festival 'The Beatles & India'", 'www.indiabeatles.ru', 1);
          portfolio.addItem('05_dashseo', "DashSeo", "DashSeo", "Design of website for promotion company", null, 1);
          portfolio.addItem('13_vsem_po_barabanu7', "Festival 'Drums for all'", "Festival 'Drums for all'", "Concept, design, filling out with content and markup", 'vsempobarabanu.info', 1);									
          portfolio.addItem('08_eralash_film', "Eralash", "Eralash", "Design of website for children's video serial", 'www.eralash.ru/today', 1);			
          portfolio.addItem('09_techno_art', "Techno Art Vision", "Techno Art Vision", "Design and markup", 'www.technoartvision.com', 1);	
          portfolio.addItem('10_moshurov2', "Moshurov", "Moshurov", "Design of website for Food Factory Moshurov", null, 1);			
          portfolio.addItem('11_geksagon2', "Geksagon", "Geksagon", "Design of website for bar coding company", null, 1);
          portfolio.addItem('12_beat_india_in', "The Beatles & India", "The Beatles & India", "Design of website for Moscow festival 'The Beatles & India'", 'www.indiabeatles.ru/programme.php', 1);			
          portfolio.addItem('12_life_style', "LifeStyle Marketing", "LifeStyle Marketing", "Design of website", 'www.lifestylemarketing.ru', 1);			
          portfolio.addItem('13_vaishnav', "ISKCON", "ISKCON", "Design of website for ISKCON forum", null, 1);
          portfolio.addItem('15_nkt', "NKT", "NKT", "Design of website for corporate website NKT", null, 1);			
          portfolio.addItem('14_friends', "Friends", "Friends", "Design and markup of website for cartoon film 'Friends'", 'www.anime.studiosvet.ru', 1);						
          portfolio.addItem('16_hugel', "Hugel", "Hugel", "Design of e-commerce website for computer hardware company", 'www.hugel.ru', 1);						
          portfolio.addItem('17_avalon', "Avalon", "Avalon", "Design of website for furniture retail", null, 1);			

            portfolio.addItem('06_enertrac_home', "Enertrac Dashboard Home", "Enertrac Dashboard Home", "Desing and interface implementation in Flex of Enertrac Dashboard for energy consulting company Nuenergen", null, 2);
            portfolio.addItem('05_enertrac_details', "Enertrac Dashboard Details", "Enertrac Dashboard Details", "Desing and interface implementation in Flex of Enertrac Dashboard for energy consulting company  Nuenergen", null, 2);
            portfolio.addItem('01_boeing', "3DMan.Boeing", "3DMan.Boeing", "Design and markup system for Luxoft company. Project for Boeing", null, 2);
            portfolio.addItem('02_sportmaster_adress', "Catalog Sportmaster", "Catalog Sportmaster", "Design and markup of catalog in Flex for Sportmaster company. Address Page.", null, 2);
            portfolio.addItem('03_sportmaster_catalog', "Catalog Sportmaster", "Catalog Sportmaster", "Design and markup of catalog in Flex for Sportmaster company. Card Page.", null, 2);
            portfolio.addItem('04_sportmaster_map', "Catalog Sportmaster", "Catalog Sportmaster", "Design and markup of catalog in Flex for Sportmaster company. Map Page.", null, 2);

            portfolio.addItem('08_logo_enertrac', "Enertrac Logo", "Enertrac Logo", "Logo design for Enertrac dashboard of energy consulting company Nuenergen", null, 3);
            portfolio.addItem('01_aromoth_cosm', "Vedic cosmetology and aromatherapy", "Vedic cosmetology and aromatherapy", "Card design for Center of Vedic Culture", null, 3);
            portfolio.addItem('01_djagannatha', "The ancient Deity of Sri Djaganatha", "The ancient Deity of Sri Djaganatha", "Card design for Center of Vedic Culture", null, 3);
            portfolio.addItem('01_indiabeatles_fr', "Invitation The Beatles & India", "Invitation The Beatles & India", "Design of invitation card for Moscow festival 'The Beatles and India'", null, 3);
            portfolio.addItem('02_indiabeatles_back', "Invitation The Beatles & India", "Invitation The Beatles & India", "Design of invitation card for Moscow festival 'The Beatles and India'", null, 3);
            portfolio.addItem('03_dolores', "Dolores", "Dolores", "Design of booklet for beauty shop 'Dolores'", null, 3);
            portfolio.addItem('04_loyalti_seminar', "Loyalty Seminar", "Loyalty Seminar", "Booklet about Loyalty Seminar", null, 3);
			portfolio.addItem('05_namaste', "Namaste", "Namaste", "Design of food ticket for food company 'Namaste'", null, 3);
			
            portfolio.addItem('camel', "Long Way In The Dunes", "Long Way In The Dunes", null, null, 4);
            portfolio.addItem('dog', "Wet Nose", "Wet Nose", null, null, 4);
            portfolio.addItem('girl', "Lucky Girl", "Lucky Girl", null, null, 4);
            portfolio.addItem('jap', "Wisdom", "Wisdom", null, null, 4);
			portfolio.addItem('stealenmilk', "Stolen Milk", "Stolen Milk", null, null, 4);

            portfolio.addItem('01_IMG_0872', "Look", "Look", null, null, 5);
            portfolio.addItem('04_IMG_0888', "Helen", "Helen", null, null, 5);
			portfolio.addItem('050_IMG_0144_cut', "God", "God", null, null, 5);
			portfolio.addItem('050_13', "Moment For Photographer", "Moment For Photographer", null, null, 5);
			portfolio.addItem('08_IMG_0886', "Moskow", "Moskow", null, null, 5);
			portfolio.addItem('09_IMG_0887', "Red Square", "Red Square", null, null, 5);
			portfolio.addItem('gold_palace', "Gold Palace", "Gold Palace", null, null, 5);
			portfolio.addItem('kerch', "Kerch", "Kerch", null, null, 5);
			portfolio.addItem('yakitoria', "Don't you believe me?", "Don't you believe me?", null, null, 5);			
			portfolio.addItem('atlantic_city', "Goodwin", "Goodwin", null, null, 5);
			portfolio.addItem('gover', "National Mall", "National Mall", null, null, 5);			
			portfolio.addItem('roof', "Walking on the roofs", "Walking on the roofs", null, null, 5);			
			portfolio.addItem('050_IMG_0980', "The Picture Of Winter", "The Picture Of Winter", null, null, 5);
			portfolio.addItem('050_IMG_1862', "Misha", "Misha", null, null, 5);
			portfolio.addItem('050_IMG_2277', "Family Dinner", "Family Dinner", null, null, 5);
			portfolio.addItem('10_4_dnya_spustya', "The 28 Days After", "The 28 Days After", null, null, 5);
			portfolio.addItem('13_IMG_0619', "From The Past", "From The Past", null, null, 5);
			portfolio.addItem('00_lonely_izba', "Lonely Izba", "Lonely Izba", null, null, 5);
			portfolio.addItem('25_IMG_0869', "Toronto", "Toronto", null, null, 5);
			portfolio.addItem('26_IMG_0870', "Near With The Death", "Near With The Death", null, null, 5);
			portfolio.addItem('27_IMG_0906', "A Lot Of Yellow", "A Lot Of Yellow", null, null, 5);
			portfolio.addItem('29_IMG_0873', "Once...", "Once...", null, null, 5);
			portfolio.addItem('34_IMG_0875', "We And They", "We And They", null, null, 5);
            this.calcSectionIndexes();
    },

    addItem: function(name, hint, displayName, desc, link, section) {
        section--;
        this.itemsCountInCategory[section]++;
        this.items[section] [this.itemsCountInCategory[section]-1]  = new PortfolioItem(name, hint, displayName, desc, link, section);
    },



    flush: function(){ // flush the items onto screen in shape of html
        for(var s = 0; s < this.sectionNames.length; s++) {
            this.addPanel(this.sectionNames[s], s);
        }

        this.addTooltip();
    },

    addPanel: function(panelTypeId, sectionNum){
        var websitesPanelCount = intDivide(this.itemsCountInCategory[sectionNum], this.ITEMS_IN_PANEL) + 1;
        for (var p = 0; p < websitesPanelCount; p++) {
            var panelId = panelTypeId + (p + 1);
            this.addCaruselPanel(panelId);
            var start = p * this.ITEMS_IN_PANEL, end = Math.min((p + 1) * this.ITEMS_IN_PANEL, this.items[sectionNum].length);
            for (var i = start; i < end; i++) {
                this.addItemToPanel(this.items[sectionNum][i], '#' + panelId);
            }

        }
    },

    sectionIndexes: [0, 0, 0, 0, 0],

    calcSectionIndexes: function(){
        this.sectionIndexes[0] = 1;
        this.sectionIndexes[1] = this.sectionIndexes[0] + 1 + intDivide(this.itemsCountInCategory[0], this.ITEMS_IN_PANEL);
        this.sectionIndexes[2] = this.sectionIndexes[1] + 1 + intDivide(this.itemsCountInCategory[1], this.ITEMS_IN_PANEL);
        this.sectionIndexes[3] = this.sectionIndexes[2] + 1 + intDivide(this.itemsCountInCategory[2], this.ITEMS_IN_PANEL);
        this.sectionIndexes[4] = this.sectionIndexes[3] + 1 + intDivide(this.itemsCountInCategory[3], this.ITEMS_IN_PANEL);
				
    },

    stepTo: function(section) {
        stepcarousel.stepTo('mygallery', this.getStartSectionIndexInCarusel(section));
    },

    getStartSectionIndexInCarusel: function(section) { // return carusel index for this section
        return this.sectionIndexes[section-1];
    },

    getCurrentSection: function() {
        var currentIndex = statusA;
        if (currentIndex < this.sectionIndexes[1]) {
            return 1;
        } else if (currentIndex >= this.sectionIndexes[1] && currentIndex < this.sectionIndexes[2]){
            return 2;
        } else if (currentIndex >= this.sectionIndexes[2] && currentIndex < this.sectionIndexes[3]) {
            return 3;
        } else if (currentIndex >= this.sectionIndexes[3] && currentIndex < this.sectionIndexes[4]) {
            return 4;			
        }  else {
            return 5;
        }
    },

    changeTopLineColor: function() {
        $('.top_line_marker').animate( { backgroundColor: '#' + this.topLineColors[this.getCurrentSection()-1] }, { queue: true, duration: 700 });
//        $('.top_line_marker').css({backgroundColor: '#' + topColors[statusA-1]});
    },

    addCaruselPanel: function(id) { /** Add panel to carusel and assign given id to it. */
        var addPanelPattern = '<div class="panel" id="%s"><div class="page_items_owner"><div class="work_gallery"><ul></ul></div></div></div>';
        $('#mygallery .belt').printf(addPanelPattern, id);
    },

    addItemToPanel: function(item, panelSelector) {
        this.pictureIndex++;
        var pathPrefix = this.getPrefixPath(item.section);
        var     bigImagePath = pathPrefix + item.name + '_b.jpg',
                iconPath = pathPrefix + item.name + '_s.jpg',
                refId = 'portfolioRef' + this.pictureIndex,
                imgId = 'portfolioImg' + this.pictureIndex;


        var itemPatern = '<li><a title="" href="%s" id="%s"><img id="%s" class="tooltipped" src="%s"></a></li>';
        var gallerySelector = panelSelector + ' .work_gallery ul';
        $(gallerySelector).printf(itemPatern, bigImagePath, refId, imgId, iconPath);

        document.getElementById(imgId).item = item;
        document.getElementById(refId).item = item;

    },

    getPrefixPath: function(section) {
        return this.pathPrefixes[section];
    },

    addTooltip: function() {
        var xOffset = -10;
        var yOffset = -10;
        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result

//        var popupPattern = '<div id="mytooltip" class="%s"><div></div></div><div class="tooltip_content">%s</div>';
        var popupPattern = '<div id="mytooltip" class="%s"><div></div></div>' +
                '<div id="tooltip_content">%s<br/>%s</div>';

        $(".tooltipped").hover(function(e) {
            var currentSection = portfolio.getCurrentSection();
            var styleName = "sectionHint" + currentSection;

            $("body").printf(popupPattern, styleName, portfolio.sectionTitles[currentSection-1], this.item.hint);
            $("#mytooltip div").ifixpng();
            $("#mytooltip, #tooltip_content")
                    .css("top", (e.pageY - xOffset) + "px")
                    .css("left", (e.pageX + yOffset) + "px");
        },
                function() {
                    $("#mytooltip, #tooltip_content").remove();
                });

        $(".tooltipped").mousemove(function(e) {
            $("#mytooltip, #tooltip_content")
                    .css("top", (e.pageY - xOffset) + "px")
                    .css("left", (e.pageX + yOffset) + "px");
        });
    }


}


function PortfolioItem(name, hint, displayName, desc, link, section){
    this.name = name;
    this.hint = hint;
    this.displayName = displayName;
    this.desc = desc;
    this.link = link;
    this.section = section;

    this.getInfo = function() {
        var titleImg = null;
        if (this.displayName) {
            titleImg = '<b>' + this.displayName + '</b>'
        }

        if (this.desc) {
            if (titleImg) titleImg += '<br/>';
            titleImg += '<span style="font-size: 9px;">' + this.desc + '</span>';
        }

        if (this.link) {
            if (titleImg) titleImg += '<br/>';
            titleImg += '<a href="http://' + this.link +'">'+this.link+'</a>';
        }
        return titleImg;
    }
}

function getCookie(Name) {
    var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair
    if (document.cookie.match(re)) //if cookie found
        return document.cookie.match(re)[0].split("=")[1]; //return its value
    return null;
}


function setCookie(name, value) {
    document.cookie = name + "=" + value;
}


/** integer division */
function intDivide ( numerator, denominator ) {
    var remainder = numerator % denominator;
    return ( numerator - remainder ) / denominator;
}


function addIteractiveItem(idName, initShift, onHoverShift, width) {
    var parentSelector = '#' + idName, innerSelector = '#' + idName + ' div';
    
    if (width) $(parentSelector).css('width', width);
    $(innerSelector).css('top', initShift);
   
    $(parentSelector).hover(
            function() {
                document.body.style.cursor = 'pointer';
                $(parentSelector).css('background-position', '0 0');
                $(innerSelector).css('top', onHoverShift);
            },
            function() {
                document.body.style.cursor = 'default';
                $(innerSelector).css('top', initShift);
            });
}

function setupCommonNavElement() {
    addIteractiveItem('websites_menu', 0, -144, 65);
    addIteractiveItem('interfaces_menu', -24, -168, 70);
    addIteractiveItem('graphic_menu', -48, -192, 110);
    addIteractiveItem('illustration_menu', -96, -239, 83);
//    addIteractiveItem('illustration_menu', -96, -280, 83);
    addIteractiveItem('photography_menu', -72, -216, 95);
    addIteractiveItem('contacts_menu', -120, -264, 63);

    addIteractiveItem('main_page_bm', 0, -63, 65);
    addIteractiveItem('english_language_bm', -21, -84, 45);
    addIteractiveItem('russian_language_bm', -42, -105, 52);
}


function getParameter(queryString, parameterName) {
    // Add "=" to the parameter name (i.e. parameterName=value)
    var parameterName = parameterName + "=";
    if (queryString.length > 0) {
        // Find the beginning of the string
        begin = queryString.indexOf(parameterName);
        // If the parameter name is not found, skip it, otherwise return the value
        if (begin != -1) {
            // Add the length (integer) to the beginning
            begin += parameterName.length;
            // Multiple parameters are separated by the "&" sign
            end = queryString.indexOf("&", begin);
            if (end == -1) {
                end = queryString.length
            }
            // Return the string
            return unescape(queryString.substring(begin, end));
        }
        // Return "null" if no parameter has been found
        return null;
    }
}
