// initialise plugins
jQuery(function(){
	jQuery('ul.sf-menu').superfish();
	jQuery('#mycarousel,#mycarouselinside').jcarousel();
});
$(document).ready(function() {
	$('.tab_viewall, .viewallmenu').mouseover(function() {
		$('.viewallmenu').toggleClass('show');
		$('.tab_viewall').addClass('fakehoverviewall');
	}).mouseout(function() {
		$('.viewallmenu').toggleClass('show');
		$('.tab_viewall').removeClass('fakehoverviewall');
	});
	$('.mainpreview_img, .tab_magnify').mouseover(function() {
		$('.tab_magnify').addClass('show');
	}).mouseout(function() {
		$('.tab_magnify').removeClass('show');
	});
	$("a[rel='cbImage']").colorbox({ transition: "fade" });
	$("a[rel='cbImageMag']").colorbox({ transition: "fade" });
	$(".iframe").colorbox({ width: "80%", height: "80%", iframe: true, transition: "fade" });
	$(".iframe_installiq").colorbox({ width: "750", height: "520", iframe: true, scrollbars: false, transition: "fade" });
	$('.itemscroll_itemhead').each(function() {
		curItemScrollLength = $(this).text().length;
		if (curItemScrollLength > 28) {
			$(this).html($(this).text().slice(0, 28) + "&hellip;");
		}
	});
	$('.itemlisting').mouseover(function() {
		$(this).css({ 'position': 'relative' });
	});
	$('.itemlisting').mouseout(function() {
		$(this).css({ 'position': 'static' });
	});
	$('.infobar_download').mouseover(function() {
		$(this).find("div").show();
	});
	$('.itemlisting').mouseout(function() {
		$(this).find(".infobar_installiq").hide();
	});
	$('.sf-menu li ul li ul').each(function() {
		if ($(this).find('li a').length > 0) {
			//Nothing; continue to display normally
		} else {
			$(this).find('li').hide();
			$(this).parent().css('background-image', 'none');
		}
	});
	$('.sf-menu li ul li:first-child').each(function() {
		$(this).find('ul .h_navigation_l2_roundt').css('display', 'none');
	});

	$('.item_download').mouseover(function() {
		$('.item_download').css('background-position', 'top right');
	}).mouseout(function() {
		$('.item_download').css('background-position', 'top left');
	});

	$('.top_login_box_btn img').click(function() {
		if ($('.login_user').val() != "" && $('.login_pass').val() != "") {
			var COOKIE_NAME = 'login_cookie';
			var optionsTendays = { path: '/', expires: 10 };
			var optionsSess = { path: '/' };
			if ($('.login_remember:checkbox:checked').val() == "on") {
				$.cookie(COOKIE_NAME, 'logged', optionsTendays);
			} else {
				$.cookie(COOKIE_NAME, 'logged', optionsSess);
			}
			location.href = "/StaticPages/Freeze/FreezeMembers.aspx";
		} else {
			if ($('.login_user').val() == "") {
				$('.top_login_box_label_req_user').show();
			} else {
				$('.top_login_box_label_req_user').hide();
			}
			if ($('.login_pass').val() == "") {
				$('.top_login_box_label_req_pass').show();
			} else {
				$('.top_login_box_label_req_pass').hide();
			}
		}
	});
	$('.login_user, .login_pass').keyup(function(event) {
		if (event.keyCode == 13) {
			if ($('.login_user').val() != "" && $('.login_pass').val() != "") {
				var COOKIE_NAME = 'login_cookie';
				var optionsTendays = { path: '/', expires: 10 };
				var optionsSess = { path: '/' };
				if ($('.login_remember:checkbox:checked').val() == "on") {
					$.cookie(COOKIE_NAME, 'logged', optionsTendays);
				} else {
					$.cookie(COOKIE_NAME, 'logged', optionsSess);
				}
				location.href = "/StaticPages/Freeze/FreezeMembers.aspx";
			} else {
				if ($('.login_user').val() == "") {
					$('.top_login_box_label_req_user').show();
				} else {
					$('.top_login_box_label_req_user').hide();
				}
				if ($('.login_pass').val() == "") {
					$('.top_login_box_label_req_pass').show();
				} else {
					$('.top_login_box_label_req_pass').hide();
				}
			}
		}
	});
	$('.login_user, .login_pass').blur(function() {
		if ($('.login_user').val() == "") {
			$('.top_login_box_label_req_user').show();
		} else {
			$('.top_login_box_label_req_user').hide();
		}
		if ($('.login_pass').val() == "") {
			$('.top_login_box_label_req_pass').show();
		} else {
			$('.top_login_box_label_req_pass').hide();
		}
	});

	$('.sort_select select').change(function() {
		$('.simul-click').click();
	});
});

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function loginDrop() {
	$('.top_login').toggleClass('top_login_clicked');
	$('.top_login_box').toggleClass('top_login_box_toggled');
}
function loginWhatsthis() {
	$('.top_login_box_whatsthistxt').toggleClass('top_login_box_whatsthistxt_toggled');
}
function getQueryParam(parameter,str) {
    var p = escape(unescape(parameter));
    var regex = new RegExp("[?&]" + p + "(?:=([^&]*))?", "i");
    var match = regex.exec(str);
    var value = null;
    if (match != null) {
        value = match[1];
    }
    return value;
}
