var RIV = {};



function getParameters(){
    var
    url = location.href,
    settingsObject = {},
    hash,
    hashes = url.slice(url.indexOf('?')+1).replace(/&amp;/i,'&').split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        settingsObject[hash[0]] = hash[1];
    }
    return settingsObject;
}

RIV.projectNav = function(){
    var
    get = getParameters(),
    href = location.href.replace(/&view=type/,'').replace(/&view=market/,''),
    $market = $('#view-market'),
    $type = $("#view-type"),
    $marketLink,
    $typeLink;
    
    function initLinks(selector){
        var
        $list = $("#menu-view-"+selector+" > li").addClass('projectNav'),
        $projects = $list.find('ul').hide();

        $list.find('> a').click(function(e){
            var $active = $(this).parent().find('ul');
            
            if($active.length){ 
                e.preventDefault();
                $active.slideDown().parent().addClass('active');
                $projects.not($active).slideUp().parent().removeClass('active');
            }
        });
        
        $projects.find('a').each(function(){
            this.href += '&view=' + selector;
        });
    }
    
    initLinks("market");
    initLinks("type");
        
    if(get['page_id']){
        $('a[href*="' + get['page_id'] + '"]').closest('.projectNav').addClass('active').find('ul').show();
    }
    
    $marketLink = $('<a/>', {text: "Market", href: href + "&view=market", click: function(){
   		window.location = "?page_id=151&view=market"
		$(this).addClass('active');
        $typeLink.removeClass('active');
        $type.hide();
        $market.show();
        return false;
    }});

    $typeLink = $('<a/>', {text: "Project Type", href: href + "&view=type", click: function(){
        window.location = "?page_id=718&view=type"
		$(this).addClass('active');
        $marketLink.removeClass('active');
        $type.show();
        $market.hide();
        return false;
    }});
    
    if(get['view'] != 'type'){
        $type.hide();
        $marketLink.addClass('active');
    } else {
        $market.hide();
        $typeLink.addClass('active');
    }
    
    $("<p id='sort_by'>Sort By: </p>").append($marketLink).append(" | ").append($typeLink).prependTo('#sort');
}
// DANG designs updated navigation
RIV.projectNav2 = function(){
    var
    get = getParameters(),
    href = location.href.replace(/&view=type/,'').replace(/&view=market/,''),
    $market = $('#view-market'),
    $type = $("#view-type"),
    $marketLink,
    $typeLink;
    
    function initLinks(selector){
        var
        $list = $("#menu-view-"+selector+" > li").addClass('projectNav2'),
        $projects = $list.find('ul').hide();

        $list.find('> a').click(function(e){
            var $active = $(this).parent().find('ul');
            
            if($active.length){ 
                e.preventDefault();
                $active.slideDown().parent().addClass('active');
                $projects.not($active).slideUp().parent().removeClass('active');
            }
        });
        
        $projects.find('a').each(function(){
            this.href += '&view=' + selector;
        });
    }
    
    initLinks("market");
    initLinks("type");
        
    if(get['page_id']){
        $('a[href*="' + get['page_id'] + '"]').closest('.projectNav').addClass('active').find('ul').show();
    }
    
    $marketLink = $('<a/>', {text: "Market", href: href + "&view=market", click: function(){
        $(this).addClass('active');
        $typeLink.removeClass('active');
        $type.hide();
        $market.show();
        return false;
    }});

    $typeLink = $('<a/>', {text: "Project Type", href: href + "&view=type", click: function(){
        $(this).addClass('active');
        $marketLink.removeClass('active');
        $type.show();
        $market.hide();
        return false;
    }});
    
    if(get['view'] != 'type'){
        $type.hide();
        $marketLink.addClass('active');
    } else {
        $market.hide();
        $typeLink.addClass('active');
    }
    
    //$("<p id='sort_by'>Sort By: </p>").append($marketLink).append(" | ").append($typeLink).prependTo('#sort');
}
// END DANG 
// Slider Removed - see copy for code if need to reinstall
$(function() {
    $('.slider').after("<ul class='paging'>").cycle({ 
            fx:    'fade',
            speed:	500,
            timeout: 5000,
            pager: '.paging',
            pagerAnchorBuilder: function(idx, slide) {
                    return '<li><a href="#"></a></li>';
            },
            activePagerClass: 'active'
    });
    
    $('.slide').cycle({ 
            fx:    'scrollHorz',
            speed:	500,
            timeout: 0,
            preve: '#prev1',
            next: '#next1'
    });
});

      
